Closed xiaohuilam closed 5 years ago
Register and boot takes more than 40 ms, was too expensive. need to optimize.
change vendor/laravel/framework/src/Illuminate/Foundation/Application.php 's register method:
vendor/laravel/framework/src/Illuminate/Foundation/Application.php
register
/** * Register a service provider with the application. * * @param \Illuminate\Support\ServiceProvider|string $provider * @param array $options * @param bool $force * @return \Illuminate\Support\ServiceProvider */ public function register($provider, $options = [], $force = false) { ... $time1 = microtime(true) * 1000; // add this line $this->markAsRegistered($provider); $time2 = microtime(true) * 1000; // add this line dump(get_class($provider) . '::register ' . ($time2 - $time1)); // add this line ... }
and change the bootProvider method in the same file
bootProvider
/** * Boot the given service provider. * * @param \Illuminate\Support\ServiceProvider $provider * @return mixed */ protected function bootProvider(ServiceProvider $provider) { if (method_exists($provider, 'boot')) { $time1 = microtime(true) * 1000; $re = $this->call([$provider, 'boot']); $time2 = microtime(true) * 1000; dump(get_class($provider) . ': ' . ($time2 - $time1)); return $re; } }
and my analysis:
LaraveServiceProvider's first line takes 15.1708984375 microseconds. https://github.com/dingo/api/blob/d46792602a838d399dc2c84642bb1cddde1a6183/src/Provider/LaravelServiceProvider.php#L24
LaraveServiceProvider's line 30~32 takes 9.296875 microseconds https://github.com/dingo/api/blob/d46792602a838d399dc2c84642bb1cddde1a6183/src/Provider/LaravelServiceProvider.php#L30-L32
I'll watch this space, but not entirely sure there is much to optimise there.
Going to close this, not really clear there's anything on this we can/should do.
Actual Behaviour
Expected Behaviour
Register and boot takes more than 40 ms, was too expensive. need to optimize.
Steps to Reproduce
change
vendor/laravel/framework/src/Illuminate/Foundation/Application.php
'sregister
method:and change the
bootProvider
method in the same fileand my analysis:
LaraveServiceProvider's first line takes 15.1708984375 microseconds. https://github.com/dingo/api/blob/d46792602a838d399dc2c84642bb1cddde1a6183/src/Provider/LaravelServiceProvider.php#L24
LaraveServiceProvider's line 30~32 takes 9.296875 microseconds https://github.com/dingo/api/blob/d46792602a838d399dc2c84642bb1cddde1a6183/src/Provider/LaravelServiceProvider.php#L30-L32