GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — LazyLoadable Backend by paarthmadan · Pull Request #612 · ruby-i18n/i18n Conversation
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Backend | Work Performed | User | Sys | Total | Real |
|---|---|---|---|---|---|
| Simple | Eager load (:en) | 0.012764 | 0.000721 | 0.013485 | 0.013503 |
| Simple | 3 Eager loads (:en, :fr, :de) | 0.012364 | 0.000675 | 0.013039 | 0.013038 |
| LazyLoadable | Eager load (:en) | 0.004820 | 0.000330 | 0.005150 | 0.005137 |
| LazyLoadable | 3 Eager loads (:en, :fr, :de) | 0.019816 | 0.000847 | 0.020663 | 0.020674 |
Table 2: Setup with 100 files per locale, 1000 keys in each file:
| Backend | Work Performed | User | Sys | Total | Real |
|---|---|---|---|---|---|
| Simple | Eager load (:en) | 1.342190 | 0.020641 | 1.362831 | 1.363569 |
| Simple | 3 Eager loads (:en, :fr, :de) | 1.344860 | 0.018035 | 1.362895 | 1.363284 |
| LazyLoadable | Eager load (:en) | 0.478600 | 0.011205 | 0.489805 | 0.489951 |
| LazyLoadable | 3 Eager loads (:en, :fr, :de) | 1.357584 | 0.026064 | 1.383648 | 1.384148 |
The LazyLoadable backend reduces working time as it avoids loading unnecessary files. In the case when loading for a single locale, we see that the LazyLoadable backend outperforms Simple, 0.005 vs 0.013 in Table 1 and 0.4899 vs 1.363 in Table 2.
This time reduction is a function of the number of locales, so we see 3x improvements because we avoid loading 66% of the files. This scales with the number of files avoided.
Note: The LazyLoadable backend performs roughly on-par with the Simple backend when it needs to load all translations. There is additional overhead of string matching which brings down the performance in small workloads. It's negligible in any significant workloads compared to the time spent in I/O.
At Shopify, we've patched ruby-i18n locally to implement a similar strategy. We've observed close to 10x speed ups locally in specific tests and roughly 20% speeds across the suite.
This backend is designed to bring performance improvements to workloads with a large volume of locales, translation files, and translation keys.
It's designed for the local test environment, and is an opt-in backend.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This makes introspecting the translations loaded by a file easier. Maintains backwards compatability as the block is optional.
| @@ -0,0 +1,65 @@ | |||
| require 'test_helper' | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Note: This is a test used to produce the benchmarks. It will be removed before merging.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please go ahead and remove this now -- I've reviewed this PR.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@radar Done 👍
Sorry, something went wrong.
There was an error while loading. Please reload this page.
a5e3ce1 to
20ad16a
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks like a lot of great work. Thank you very much for your dedication here, @paarthmadan.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -0,0 +1,65 @@ | |||
| require 'test_helper' | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please go ahead and remove this now -- I've reviewed this PR.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
20ad16a to
422959a
Compare
|
I'll release this with a fix for #606 as the 1.10 release, ideally by next Monday. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Hello! @paarthmadan 👋 I'm working on improving performance for the faker gem. I just have a question regarding this implementation... All the best! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
In production you'd rather load all the translation as part of boot so:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Hey @salochara, I'd echo all that @casperisfine shared and add in addition that: The test environment, in particular, is the perfect candidate for lazy loading translations because:
These factors together benefit from lazy loading because we drastically reduce startup time, we only ever load translations that we need, and we only incur this penalty for tests that do actually require translations. Jean provided a great argument for why this shouldn't be used in production, but these are added reasons for why it makes added sense in the test env. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Hi! @paarthmadan @casperisfine 👋 Got it. Makes sense. Again, thank you very much for your response and the work you guys kindly put out for the community. All the best! 🙏🏼 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.