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

fix(#632) - Locale pipe optimization #637

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ben12
Copy link
Contributor

@ben12 ben12 commented Mar 19, 2023

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: #632

What is the new behavior?

Locale pipes return last formatted value when value and parameters do not change.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

Using this measurement code (and same for Date, Percent and Currency):

    pipe = new TranslocoDecimalPipe(service, cdr, defaultConfig.localeConfig);

    const config = { useGrouping: true, maximumFractionDigits: 3 };
    
    const start = performance.now();
    for(let i = 0; i < 100000; i++) {
      pipe.transform('123', config);
    }
    const end = performance.now();
    console.log(`Decimal Execution time: ${end - start} ms`);

Before optimization I get:

LOG: 'Decimal Execution time: 1708.9000000059605 ms'
LOG: 'Date Execution time: 7880.100000008941 ms'
LOG: 'Percent Execution time: 1741.4000000059605 ms'
LOG: 'Currency Execution time: 2233.5 ms'

After optimization I get:

LOG: 'Decimal Execution time: 35.19999998807907 ms'
LOG: 'Date Execution time: 47.599999994039536 ms'
LOG: 'Percent Execution time: 34.900000005960464 ms'
LOG: 'Currency Execution time: 38.70000000298023 ms'

@stackblitz
Copy link

stackblitz bot commented Mar 19, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@ben12
Copy link
Contributor Author

ben12 commented May 16, 2023

@shaharkazaz Ready for review

@shaharkazaz
Copy link
Collaborator

@ben12 Thank you for the PR and the heads up, I missed this PR.
IDK when I'll be able to review but I'll try to reach it as soon as I have the time!

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

2 participants