Bug 1893782 - Only create a single Intl.NumberFormat instance to format numbers

Currently the code creates a new instance of this class for every number that
needs to be formatted. This results in 70% of the time spent when switching to
'use replicates' being spent under internationalization code.

Creating a single instance greatly improves matters.
This commit is contained in:
Jon Coppeard 2024-07-02 10:10:50 +01:00 коммит произвёл Sebastian Hengst
Родитель c9e6ef096c
Коммит c32ec7fe66
1 изменённых файлов: 5 добавлений и 2 удалений

Просмотреть файл

@ -27,8 +27,11 @@ import {
permaLinkPrefix,
} from './constants';
export const formatNumber = (input) =>
new Intl.NumberFormat('en-US', { maximumFractionDigits: 2 }).format(input);
const numberFormat = new Intl.NumberFormat('en-US', {
maximumFractionDigits: 2,
});
export const formatNumber = (input) => numberFormat.format(input);
export const abbreviatedNumber = (num) =>
num.toString().length <= 5 ? num : numeral(num).format('0.0a');