Repository navigation
perf(grid): read thousands-separated numbers in selection stats without a copy (#1520) - #1657
Merged
Merged
Conversation
…ut a copy (#1520) Selection stats parsed a cell with a comma as double.tryParse(cell.replaceAll(',', '')), one copy per such cell on every drag update. GridSelectionCalcEngine.parseThousandsSeparated reads it from the code units: commas are skipped wherever they are, as in the copy; up to 15 significant digits and a power of ten up to 22 the value is computed exactly (an integer below 2^53 times or divided by an exact power of ten is one correctly rounded operation); longer numbers fall back to the copy. Cells without a comma still go to double.tryParse, and trim() returns the cell itself when there is nothing to trim. Checked against the copy on 500,000 random and money-shaped strings: no difference. 5,000 comma cells: 172 us instead of 382 us per pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1520.
#1614 made the comma copy conditional; this removes it. Selection stats (Sum / Avg / Min / Max under the grid) parsed every cell with a comma as
double.tryParse(cell.replaceAll(',', '')), so a drag over formatted numbers made one string per cell on every update.Change
GridSelectionCalcEngine.parseThousandsSeparatedreads the number from the code units:1,5is still 15, as before; changing that is a separate question);double.tryParse.double.tryParse, which needs no copy.trim()already returns the cell itself when there is nothing to trim, so a plain cell allocates no strings.Checked
A standalone Dart script compared it with
double.tryParse(s.replaceAll(',', ''))(results, sign of zero, NaN / infinity treated as non-numbers like the engine does):0-9 , . - + e E;1,234,567.89);5.,.5,1e22/1e23, 19+ digits,9,007,199,254,740,993,NaN,Infinity.No difference. Speed on 5,000 comma cells: 172 µs per pass instead of 382 µs, with no allocations.
Tests
grid_selection_calc_format_test.dartcompares it with the copy on a fixed list (signs, fractions, exponents, commas in odd places, long numbers, exponent overflow), checks-0, and checks that text with commas is not a number.Not run with
flutter testlocally; CI decides.