Performance Problem
g1tc4t opened this issue · 3 comments
g1tc4t commented
When loading a large translation file (a few thousand entries) the browser needs a few seconds to parse the entries.
Doing some performance investigations I found that the spread operator used in translate-message-format-compiler.ts
leads to O(n)=n²
This can be fixed to be O(n)=n
quite easily:
public compileTranslations(translations: any, lang: string): any {
if (typeof translations === "string") {
return this.compile(translations, lang);
}
return Object.keys(translations).reduce<{ [key: string]: any }>(
(acc, key) => {
const value = translations[key];
// just assign the value; no object initialization and no data copying needed
acc[key] = this.compileTranslations(value, lang);
return acc;
},
{}
);
}
Endrzei commented
lephyrus commented