Skip to content
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

Faster translations #3295

Merged
merged 5 commits into from
May 21, 2024
Merged

Faster translations #3295

merged 5 commits into from
May 21, 2024

Conversation

aatkin
Copy link
Collaborator

@aatkin aatkin commented May 15, 2024

relates #3283

Internal performance update to how translations are fetched.

Motivation

Email template transformations take quite a bit of time when large-ish number of emails are produced. For example application.event/decided creates 1 email for each workflow handler:

event-to-emails, disabled cache

handler count mean lower-q 2.5% upper-q 97.5%
1 4,780888 ms 4,097078 ms 6,170799 ms
10 52,443133 ms 49,652797 ms 55,356244 ms
50 223,241818 ms 203,445667 ms 249,808264 ms
100 441,938544 ms 413,564604 ms 478,001015 ms
200 834,458932 ms 804,961543 ms 914,037245 ms

(using 2019 Macbook Pro with 2,3 GHz 8-Core Intel Core i9)

Screenshot 2024-05-15 at 17 22 06

Caching dictionary for tempura function reduces mean time by almost 100x. For same event, but using cached translation function:

event-to-emails, cache

handler count mean lower-q 2.5% upper-q 97.5% cache size
1 40,996545 µs 39,542207 µs 43,635827 µs 882,5 KiB
10 397,217641 µs 367,224108 µs 435,834954 µs 882,5 KiB
50 2,158321 ms 1,904828 ms 2,440271 ms 882,5 KiB
100 4,206048 ms 3,757476 ms 4,956851 ms 882,5 KiB
200 8,656116 ms 7,626819 ms 10,665969 ms 882,5 KiB

Screenshot 2024-05-15 at 16 26 41

Checklist for author

Remove items that aren't applicable, check items that are done.

Reviewability

  • Link to issue (no issue number)
  • Consider adding screenshots for ease of review (clj-async-profiler)

Documentation

  • Update changelog if necessary

Testing

  • Complex logic is unit tested
  • Valuable features are integration / browser / acceptance tested automatically

Follow-up

  • New tasks are created for pending or remaining tasks

Before, tr would re-create dictionary for every translation call which is unnecessary, and also relatively slow due to how nested map is processed.

Application with 200 handler workflow attempts to send 200 emails for a single decided event. With uncached tr this can take even 700ms or more, just for text substitution! Compare to cached version which takes around 10ms.
These may not be easily checked from release to release, but maybe interesting for running with different configurations, and inspiration for other performance analysis.
@aatkin aatkin marked this pull request as ready for review May 15, 2024 14:24
Table makes it a little easier to compare multiple dimensions, and Github supports rendering markdown tables, too.
Copy link
Collaborator

@Macroz Macroz left a comment

Choose a reason for hiding this comment

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

Nice!

test/clj/rems/test_performance.clj Outdated Show resolved Hide resolved
@Macroz Macroz merged commit d431d3b into master May 21, 2024
7 checks passed
@Macroz Macroz deleted the faster-translations branch May 21, 2024 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants