-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[RFC] Transforming Intl data from JSON to PHP #23545
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
Comments
Bernhard did a test before deciding on a format: https://github.com/webmozart/json-res-benchmark |
@mvrhov thanks for the reference! According to the benchmark results, JSON is the worst format for performance. |
The discussion is here #11920 |
@mvrhov in the discussion, Bernhard demonstrated that JSON is not only the slowest format ... but also the biggest in size (because, unlike PHP, can't save UTF8 chars directly). And all this is before the massive improvements introduced by PHP 7. The difference between PHP and JSON would be even bigger today. |
I'm not against it. And have no idea why @webmozart at the end decided to use json. |
👍 to do it, static arrays in shared memory rulez. |
👍 I'll have a look |
would it be possible to reuse the benchmark of https://github.com/webmozart/json-res-benchmark to see what happens when using static arrays in shared memory ? |
PHP 7.1.10 Memory & Peak Memory 2048kB in all cases. Notes:
Previous benchmarks in brackets. Results (opcache disabled)
Results (opcache enabled)
|
I think the reason why json was chosen might've been @bojanz'es comment:
and @rszrama's
|
@jakzal what would be your recommendation? Switch to PHP? Keep things unchanged? Thanks! |
@javiereguiluz research in progress ;) |
@javiereguiluz do you remember which page were you profiling exactly? |
I don't remember, so I profiled several pages again. The time spent on this Blog index: http://symfony-demo.test/en/blog/ Blog show: http://symfony-demo.test/en/blog/posts/lorem-ipsum-dolor-sit-amet-consectetur-adipiscing-elit Backend index: http://symfony-demo.test/en/admin/post/ |
I made some profiling too, but with 2-3ms overhead for json_decode it's hard to observe significant differences:
Still, my previous raw tests show that php format is over twice faster than json (even if it's just 1.12ms vs 2.84ms). |
After being loaded, is the translation array ever modified? Like merged with others, or entries added before being used? If yes, that should be fixed first: this would kill all the potential benefit. |
It's returned right away without modifications: https://github.com/symfony/intl/blob/master/Data/Bundle/Reader/PhpBundleReader.php#L54 |
Will this still get merged then |
It's surprising that the memory usage doesn't drop, that's why I'm asking. Should be double checked to ensure the return value itself is not triggering COW. (Sorry can't check now) |
I rerun the benchmarks. PHP 7.3-rc
PHP 7.2
PHP 7.1
PHP 7.0
PHP 5.6
PHP 5.5
|
Entries are being merged in some cases: https://github.com/symfony/intl/blob/master/Data/Bundle/Reader/BundleEntryReader.php#L101-L122 |
@javiereguiluz @nicolas-grekas what are your opinions on this? I'd like to either make the conversion soon, or close this :) Any more tests/benchmarks I could do? |
If no one can foresee technical issues by making this change, I'd say that the conversion from JSON to PHP is a no brainer. You get a significant performance improvement "for free". |
I agree with @javiereguiluz if it's a free performance gain and it does not change anything in the memory spent then this can be done ;). cc @jakzal |
I made an app gain a +1000% performance boost in average by changing some config files from JSON to PHP. Costless, painless, performance gain. |
And by the way, it seems that it's only a few lines of changes in the |
@Pierstoval thank you for sharing your results. Impressive! Thank you for reminding me about this. It's been long on my list of things to do. Let me submit a PR for this to finally make this happen! |
Nice thank you @jakzal |
@jakzal I started the work on my machine (this is also why I noticed the change is not "that big"), if you want I can submit it :) |
@Pierstoval it's fine. I also started it, just need to refresh and run performance tests again. |
@jakzal @Pierstoval What is the state of your work on this issue? Is there a chance to have it in 4.4? |
sorry for the delay. I was waiting for a new icu release (which has happened now). I’ll rerun my tests this weekend and send a pr. |
It’s a very interesting thread, thank you all for the discussions, benchmarks and feedback. I read sometimes that using named classes with public properties are the „fastest“ choice. Sorry I cannot get the source and to be honest, I am not that deep into those topics. But would you consider using a class over an assoc array? Thanks for the info 👍🏻 |
Named classes can be faster because they're always passed as references, so it may improve perfs a bit because arrays are passed as copy. However, with copy-on-write for arrays and engine array optimizations from latest PHP versions, I'm not sure it's really useful to use a class rather than a plain PHP array. Maybe PHP experts could correct me if I'm wrong |
Arrays will always be faster thanks to copy-on-write. Classes in PHP 7.4 might be as fast, but not in earlier versions. Of course, this supposes we do NO operations on the loaded arrays. Anything that would trigger COW would break the perf benefit. |
Thank you very much for the clarification 🙂 |
Thank you for this suggestion. |
Could I get an answer? If I do not hear anything I will assume this issue is resolved or abandoned. Please get back to me <3 |
Hey, I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen! |
This PR was merged into the 5.3-dev branch. Discussion ---------- [Intl] Switch from json to php resources | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #23545 | License | MIT | Doc PR | - take over #34214 Commits ------- 24bfc3b [Intl] Switch from json to php resources
I was profiling the Symfony Demo app, and I realized that
json_decode()
took a lot of time to execute:The reason is that Intl data is provided as JSON files (see https://github.com/symfony/symfony/tree/master/src/Symfony/Component/Intl/Resources/data).
Would it make sense to transform that data into PHP (using
var_export()
) to avoid parsing it and to get free caching thanks to OPCache? By the way, Intl already provides a reader and writer of this data for PHP, so we could use it (see https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Intl/Data/Bundle/Reader/PhpBundleReader.php).The text was updated successfully, but these errors were encountered: