Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: prune flagged autoload files #1

Closed
ChrisLightfootWild opened this issue Jun 26, 2024 · 2 comments
Closed

Idea: prune flagged autoload files #1

ChrisLightfootWild opened this issue Jun 26, 2024 · 2 comments

Comments

@ChrisLightfootWild
Copy link

Hey 👋

I wanted to propose additional functionality to prune any composer autoload files which become redundant if the spi plugin is allowed to run. I suspect that isn't always the case, but for certain packages we could remove the (usually minor) overhead of the autoload file which would otherwise be loaded at every runtime.

A couple of examples which OpenTelemetry packages may benefit from:


I started an implementation which I was playing with as a proof-of-concept:

ChrisLightfootWild/opentelemetry-php@6125b71

However, it seems like behaviour which would make more sense to reside within the SPI package directly.

Thanks!

@Nevay Nevay closed this as completed in 34ea960 Jun 30, 2024
@Nevay
Copy link
Owner

Nevay commented Jun 30, 2024

34ea960 adds two configuration options:

  • extra.spi-config.prune-autoload-files basically does the same as your proof-of-concept
  • extra.spi-config.autoload-files creates a static map from ServiceLoader::register() calls within autoload.files,
    which removes the need to duplicate service definitions in extra.spi and ServiceLoader::register().

Using open-telemetry/opentelemetry-php-contrib#269 as example, should be able to use:

  "extra": {
+   "spi-config": {
+     "autoload-files": true
+   },
    "spi": {
      "OpenTelemetry\\Config\\SDK\\Configuration\\ComponentProvider": [
        "OpenTelemetry\\Contrib\\Instrumentation\\Laravel\\LaravelComponentProvider"
-     ],
-     "OpenTelemetry\\API\\Instrumentation\\AutoInstrumentation\\Instrumentation": [
-       "OpenTelemetry\\Contrib\\Instrumentation\\Laravel\\LaravelInstrumentation"
-     ],
-     "OpenTelemetry\\Contrib\\Instrumentation\\Laravel\\Hooks\\Hook": [
-       "OpenTelemetry\\Contrib\\Instrumentation\\Laravel\\Hooks\\Illuminate\\Console\\Command",
-
-       "OpenTelemetry\\Contrib\\Instrumentation\\Laravel\\Hooks\\Illuminate\\Contracts\\Console\\Kernel",
-       "OpenTelemetry\\Contrib\\Instrumentation\\Laravel\\Hooks\\Illuminate\\Contracts\\Http\\Kernel",
-       "OpenTelemetry\\Contrib\\Instrumentation\\Laravel\\Hooks\\Illuminate\\Contracts\\Queue\\Queue",
-
-       "OpenTelemetry\\Contrib\\Instrumentation\\Laravel\\Hooks\\Illuminate\\Foundation\\Console\\ServeCommand",
-       "OpenTelemetry\\Contrib\\Instrumentation\\Laravel\\Hooks\\Illuminate\\Foundation\\Application",
-
-       "OpenTelemetry\\Contrib\\Instrumentation\\Laravel\\Hooks\\Illuminate\\Queue\\Queue",
-       "OpenTelemetry\\Contrib\\Instrumentation\\Laravel\\Hooks\\Illuminate\\Queue\\SyncQueue",
-       "OpenTelemetry\\Contrib\\Instrumentation\\Laravel\\Hooks\\Illuminate\\Queue\\Worker"
      ]
    }
  },

@ChrisLightfootWild
Copy link
Author

@Nevay amazing, thank you for doing this. I have just tried it out and it's working as desired ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants