plone / plone.i18n

Text normalization logic and language, country, cctld data.
8 stars 11 forks source link

Optimize performance of the language utility #47

Open davisagli opened 1 year ago

davisagli commented 1 year ago

Language negotiation uses the settings property of the language utility a lot. Each time it constructs a new copy of the language settings, so let's memoize it. This isn't a huge amount of clock time (< 1ms) but it was enough to show up in some profiling I was doing, and it's easy to make it 6.6 times faster by doing this (0.99ms -> 0.15ms on my laptop).

mister-roboto commented 1 year ago

@davisagli thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically.

Happy hacking!

davisagli commented 1 year ago

@jenkins-plone-org please run jobs

davisagli commented 1 year ago

Well, it's clearly not as straightforward as I thought, and the memoized value is being used too long in tests.

jensens commented 1 year ago

I am +/-0 for this one.

Your PR brings up again an idea I have in my head for 1-2 years. I would like to handle this (caching the registry lookup) on a global level. My idea is to just set the registry as an attribute of the request on traversal (then lineage.registry can update this attribute) and use it everywhere. This should speed up Plone a lot. My profiler sessions all showed registry lookup is eating up significant milliseconds.

So yes we can merge this, but in the long run we need a better solution.

davisagli commented 1 year ago

@jensens I like your idea.

mauritsvanrees commented 1 year ago

I was looking at old branches in this package, and saw this one, and saw that @jaroel tried exactly the same in the closed PR #34. :-)

A general cached registry lookup on the request sounds nice.

jensens commented 1 year ago

I created a PLIP https://github.com/plone/Products.CMFPlone/issues/3728

jaroel commented 1 year ago

I was looking at old branches in this package, and saw this one, and saw that @jaroel tried exactly the same in the closed PR #34. :-)

I guess I have some good ideas after all! :)