-
Notifications
You must be signed in to change notification settings - Fork 489
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
performance: implement caching for roundDecimal() and prevent unnecessary recalculations #642
Conversation
…sary recalculations
I'm still puzzled how a hashtable lookup can be faster that truncating a stringified float. Is this truncating function really needed for standard compliance ? or is it for a cosmetic purpose ?
anyway, it's good to see some love about performance. |
The costly part is |
I'm already storing that in the variable |
I'll take a look at this after my system's done updating. |
I'm struggling to understand the need for a loss precision function. can you show me an example of expected input-output for this ? hopefully it will help me grasp the idea. |
I tried out several rounding methods at the time, starting with a simple Here is a short blog post about the issues with floating-point arithmetics: https://www.jacklmoore.com/notes/rounding-in-javascript/ |
It might be possible to do this using a typed array/array buffer to do it correctly. |
Description
Implement caching for decimal rounding by storing the results for the decimal part of floats only and adding them to the significant part. Also avoid unnecessary recalculations by storing the value for reuse.
fixes #641
Motivation and Context
Using our performance test tool, we could see a huge drop (~1s vs ~6s) in performance from 1.3.4 to the current master. The culprit seems to have been the function
roundDecimal()
inpath.js
alone. That calculation seems to be very performance-hungry, however, it's the only way that I found so far to get reliable rounding of floats without losing precision.How Has This Been Tested?
Using the performance test tool in
docs/benchmark.html
comparing to version 1.3.4 before and after the optimization. Also rannpm run test
as well as the unicode test tool to make sure it doesn't break passing tests.Screenshots (if appropriate):
before
after
Types of changes
Checklist:
npm run test
and all tests passed green (including code styling checks).I have added tests to cover my changes.(not applicable)