-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[Laravel] Service Provider performance #1776
Comments
Nope, it's a lot more methods (all week methods for example will use first_day_of_week and day_of_first_week_of_year of the locale), getters for month and week days names (short and long), isoFormat, parseFromLocale, translateTimeString, it's used by CarbonInterval and CarbonPeriod. So intercepting all this function to lazy load the messages is not really an option.
Not an option neither as we don't know in advance the locale (it can be any language with any region among hundreds). Cache is app-specific, the locale is in most cases user-specific (get from BD, session, cookie, etc.) If your app is 100% in English or does not need any translation for date, adding Carbon ServiceProvider in
You can only get this using |
Sorry, I shouldn't have said 'No penalty', I indeed mean very little. I do now realize that part of the time might be from actually loading Carbon itself, which is triggered by the setLocale, instead of later when Carbon is first used, so the penalty 'in real life' would probably be smaller. |
However there are still good improvements in your PR, maybe I will keep all but the setDefaultLocale method. Then working on translations performances globally (not in the particular case of the Laravel boot). It's in the road-map:
|
Hmm, it's hard to pinpoint exactly, but I think it's probaby not the Locale call itself, so closing this for now. Thanks for the feedback! |
Hello,
So I'm probably nitpicking here about 0.5ms, but anyways, Re: #1363
In light of checking the Laravel boot performance, I was checking which service providers are making the biggest impact on the boot time for a 'hello world' request. The Carbon ServiceProvider stood out because it took more time then other providers. (And because it is required by Laravel itself, but auto-registered, it's easy to miss because it's not there with the rest).
I'm not sure what
setLocale
actually does, but it seems to create a Translator instance and load the message from disk. In regards with performance on an optimized config (see https://twitter.com/barryvdh/status/1147547152366874628) I get +/- 3ms to reach the Controller. If I put Carbon in thedont-discover
list, it drops about 0.5ms. Which obviously isn't a lot an absolute terms, but it's still about 16% of the entire boot of Laravel.Removing the ServiceProvider now would obviously break lot's of projects, but does the
setLocale
need to be this heavy? Am I doing something wrong (seeing the result on opcached production, but also on Valet+)?Possible solutions:
Issue Tempate:
I encountered an issue with the following code:
Carbon version: 2.20.0
PHP version: 7.2.8 / 7.3.6
I expected to get: No performance penalty for booting Laravel
But I actually get: 0.5ms 'delay' when using the ServiceProvider
The text was updated successfully, but these errors were encountered: