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

External memoization #218

Open
zbraniecki opened this issue Jun 4, 2018 · 1 comment
Open

External memoization #218

zbraniecki opened this issue Jun 4, 2018 · 1 comment

Comments

@zbraniecki
Copy link
Collaborator

In #217 I'm proposing an FTLResource class to store parsed FTL resources.

Another vector of cleaning up the role of MessageContext as a immutable container is to avoid duplication of intl memoization between multiple contexts.

Currently, if we create one context for ["res1.ftl", "res2.ftl"] and one context for ["res2.ftl", "res3.ftl"], we'll get two storages of intl objects. In the scenario Firefox operates in, that redundancy is not necessary, and adds a cost to dynamic recreation of contexts when the list of resources changes.

I'd like to suggest an optional external memoization model which could be shared across MessageContext instances:

let memoizer = new IntlMemoizer();
let ctx = new MessageContext(locales, [res1, res2], { memoizer });
ctx = new MessageContext(locales, [res1, res2, res3], { memoizer });

In this model, invalidating ctx1 when res3.ftl is added is very cheap.

In the example above I even folded addMessages/loadResource into the constructor, but if you prefer to keep it as a separate method, it would work the same way.

@stasm, @Pike - thoughts?

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

No branches or pull requests

2 participants