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

perf(plugins): decrease number of calls to translate all extensions only once #1359

Merged
merged 4 commits into from Jan 23, 2024

Conversation

ghiscoding
Copy link
Owner

@ghiscoding ghiscoding commented Jan 22, 2024

found a couple of places in the code where it was translating the same things more than once

  • translateAllExtensions() is calling translate on all extensions including a call to translateColumnHeaders() but that one was also calling GridMenu translates which was already translated, instead we can expect that translateColumnHeaders() should also indirectly translate both ColumnPicker/GridMenu only once inside renderColumnHeaders() when reassigning translated columns
  • also translateColumnHeaders() will indirectly call a grid.invalidate() so I think this call should be made last in translateAllExtensions() so that everything else had a chance to be translated prior to reaching the invalidate
  • onLanguageChange is calling translateAllExtensions() but was also calling translateColumnHeaderTitleKeys() and translateColumnGroupKeys(), however these last 2 were already covered by translateColumnHeaders() so they can be removed
  • also a rare but potential infinite loop could happen if translateColumnHeaders() is provided with a lang, which then triggers a onLanguageChange which then calls back translateColumnHeaders() which could become infinite, so we should make sure that we only trigger a lang change event only when we see the lang being different
  • another small perf improvement, there's no need to check if the translateXYZ methods exists on each extensions because we already know it exists (that code was put in place when we were using the external 6pac/SlickGrid dependency, but now everything is internal and we know all these methods already exists since it must follow the interface), e.g.
translateGridMenu() {
-    this._gridMenuControl?.translateGridMenu?.();
+    this._gridMenuControl?.translateGridMenu();
}

found a couple of places in the code where it was translating the same things more than once, for example
- `translateAllExtensions()` is calling translate on all extensions including a call to `translateColumnHeaders()` but that one was also calling GridMenu translates which was already translated, instead we can expect that `translateColumnHeaders()` should also indirectly translate both ColumnPicker/GridMenu only once
- `onLanguageChange` is calling `translateAllExtensions()` but was also calling `translateColumnHeaderTitleKeys()` and `translateColumnGroupKeys()`, however these last 2 were already covered by `translateColumnHeaders()` so they can be removed
- also a rare but potential infinite loop could happen if `translateColumnHeaders()` is provided with a lang, which then triggers a `onLanguageChange` which then calls back `translateColumnHeaders()` which could be come infinite, so we should make sure that we only trigger a lang change event when the lang is really different
- another small perf improvement, there's no need to check if the translateXYZ method exists on each extensions because we know it exists (that code was put in place when we were using the extenral 6pac/SlickGrid but now everything is internal and we know all these methods exists since it must follow the interface), e.g.
```diff
translateGridMenu() {
-    this._gridMenuControl?.translateGridMenu?.();
+    this._gridMenuControl?.translateGridMenu();
}
```
@ghiscoding
Copy link
Owner Author

@zewa666 here's is a first PR to fix multiple translate calls, I wasn't sure if I should name this PR as fix or perf because it really does both. You can review if you want, I'll probably merge soon anyway

Copy link

codecov bot commented Jan 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (91426d1) 99.7% compared to head (418223f) 99.7%.

Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1359     +/-   ##
========================================
- Coverage    99.7%   99.7%   -0.0%     
========================================
  Files         199     199             
  Lines       21576   21564     -12     
  Branches     7202    7199      -3     
========================================
- Hits        21496   21484     -12     
  Misses         73      73             
  Partials        7       7             

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

ghiscoding-SE and others added 3 commits January 22, 2024 18:26
- we already update the columnswith their translations inside `renderColumnHeaders()` so no need to retranslate the extensions again
@ghiscoding ghiscoding changed the title fix(common): translate all extensions only once perf: decrease number of calls to translate all extensions only once Jan 23, 2024
@ghiscoding ghiscoding changed the title perf: decrease number of calls to translate all extensions only once perf(plugins): decrease number of calls to translate all extensions only once Jan 23, 2024
@zewa666
Copy link
Contributor

zewa666 commented Jan 23, 2024

its good to know the tracing of calls to invalidate but I wonder whether this method perhaps should be debounced so that multiple calls are batched into a single one

@ghiscoding
Copy link
Owner Author

its good to know the tracing of calls to invalidate but I wonder whether this method perhaps should be debounced so that multiple calls are batched into a single one

I don't really want to add debounce since that would require 1 more cycle before the invalidate kicks in, and this PR is about translation calls, not really invalidate which I'm looking at to do in another PR. There's no call to invalidate at all in this current PR, I did mention about it in the description but it's mainly about the order of execution

@zewa666
Copy link
Contributor

zewa666 commented Jan 23, 2024

yeah I got that and the additional cycle is yet another argument. the core fix in itself makes absolut sense as there's no reason for that additional emit if lang stays the same

@ghiscoding
Copy link
Owner Author

I think the PR is ok, so let's merge and a follow up PR is coming for invalidate()

@ghiscoding ghiscoding merged commit 3e002f1 into master Jan 23, 2024
5 checks passed
@ghiscoding ghiscoding deleted the perf/translate-only-once branch January 23, 2024 14:29
ghiscoding added a commit to ghiscoding/Angular-Slickgrid that referenced this pull request Jan 24, 2024
ghiscoding added a commit to ghiscoding/Angular-Slickgrid that referenced this pull request Jan 24, 2024
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

3 participants