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

Create instance own localize method #209

Merged
merged 2 commits into from
Nov 14, 2024
Merged

Conversation

bearfriend
Copy link
Contributor

Each instance of the Localize class should have its own (as in hasOwn) localize method to store its resources and other localization-related state.

This is not applied to the LocalizeClass so that other uses, like for component mixins, can continue to share resources per-component. There is some light additional work to be done in core to fully take advantage of this because it's currently re-fetching for each element even if the component has its resources. However, that can be done separately from this change.

Using getPrototypeOf/super instead of bind has the advantage of keeping the shared localize method and not hogging memory, with no hit to speed.

@bearfriend bearfriend requested a review from a team as a code owner November 12, 2024 19:45
@bearfriend
Copy link
Contributor Author

bearfriend commented Nov 12, 2024

Well I'll be! Getting difference benchmark results today, showing getPrototypeOf being slower, but still absurdly fast. Using super, though, is actually faster.

Edit: My laptop battery was just dying and affecting the results. Plugged it in and they're all basically the same within well below 1%

@@ -214,6 +214,7 @@ export const Localize = class extends getLocalizeClass() {
constructor(config) {
super();
super.constructor.setLocalizeMarkup(localizeMarkup);
this.localize = (...args) => super.localize(...args);
Copy link
Member

Choose a reason for hiding this comment

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

Haha really that was it?! 💯 Is there a way to have a test that would have failed before when they were sharing resources but now passes?

@bearfriend bearfriend merged commit 37eae40 into main Nov 14, 2024
1 check passed
@bearfriend bearfriend deleted the dgleckler/own-localize branch November 14, 2024 15:41
Copy link

🎉 This PR is included in version 3.19.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants