Skip to content

[Translator] Many performance improvements on the cache warming#2206

Merged
Kocal merged 7 commits intosymfony:2.xfrom
Kocal:imp-translations-cache-warmer-perf
Sep 26, 2024
Merged

[Translator] Many performance improvements on the cache warming#2206
Kocal merged 7 commits intosymfony:2.xfrom
Kocal:imp-translations-cache-warmer-perf

Conversation

@Kocal
Copy link
Copy Markdown
Member

@Kocal Kocal commented Sep 25, 2024

Q A
Bug fix? no
New feature? no
Issues Fix #...
License MIT

The Symfony UX Translator cache warmer can be an long task, especially if your app has a lot of translations.

I was able to identify some bottlenecks and fix them, with a dedicated commit for each of them.

My test application have ~25k translation keys (3.119 keys * 8 locales). Of course that's a lot, but I believe some people needs to dump all their translations (e.g. if they build an SPA on Symfony). For "more classic" applications, it is recommended to use dedicated domains for translations JS-side.

Anyway, in my application, I was able to reduce the Translator cache warming from 2m11s (higher than the reality, because of Blackfire profiling) to 41s (higher than the reality, because of Blackfire profiling):
image

The vast majority of improvements come from better use of the Symfony String component.

Blackfire profiles:

  1. Initial
  2. Re-using s() instances
  3. Removing useless s()->slice()
  4. Caching $this->message->length() as it will always return the same length
  5. Before/After: ~63% 🚀

Also, since the Translator component is still experimental, I've marked some classes as final and internal, as they should only be used internally. :)

@carsonbot carsonbot added the Status: Needs Review Needs to be reviewed label Sep 25, 2024
@Kocal Kocal force-pushed the imp-translations-cache-warmer-perf branch from 969c6cf to 1309032 Compare September 25, 2024 14:25
Copy link
Copy Markdown
Member

@smnandre smnandre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trusting you here :)

@Kocal Kocal force-pushed the imp-translations-cache-warmer-perf branch 2 times, most recently from 7b38d80 to 4f3c9e4 Compare September 26, 2024 05:37
@Kocal Kocal force-pushed the imp-translations-cache-warmer-perf branch from 4f3c9e4 to 02e1eb3 Compare September 26, 2024 05:39
@carsonbot carsonbot added Status: Reviewed Has been reviewed by a maintainer and removed Status: Needs Review Needs to be reviewed labels Sep 26, 2024
Copy link
Copy Markdown
Member

@smnandre smnandre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤝

@Kocal Kocal merged commit 6330ad1 into symfony:2.x Sep 26, 2024
@Kocal Kocal deleted the imp-translations-cache-warmer-perf branch September 26, 2024 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Performance Status: Reviewed Has been reviewed by a maintainer Translator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants