Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Issue 518093002: Optimize number-to-string conversions. (Closed)

Created:
6 years, 3 months ago by koda
Modified:
6 years, 3 months ago
CC:
reviews_dartlang.org, vm-dev_dartlang.org
Visibility:
Public.

Description

Optimize number-to-string conversions. Add lookup table for ints in [-99, 99] and a cache for doubles. R=iposva@google.com Committed: https://code.google.com/p/dart/source/detail?r=39710

Patch Set 1 #

Patch Set 2 : #

Patch Set 3 : #

Patch Set 4 : #

Patch Set 5 : #

Patch Set 6 : #

Patch Set 7 : #

Total comments: 7
Unified diffs Side-by-side diffs Delta from patch set Stats (+54 lines, -9 lines) Patch
M runtime/lib/double.dart View 1 2 3 4 5 6 1 chunk +27 lines, -0 lines 3 comments Download
M runtime/lib/integers.dart View 1 2 3 2 chunks +27 lines, -9 lines 4 comments Download

Messages

Total messages: 7 (1 generated)
koda
6 years, 3 months ago (2014-08-29 14:34:51 UTC) #1
koda
6 years, 3 months ago (2014-08-29 18:20:43 UTC) #2
Ivan Posva
LGTM -ip https://codereview.chromium.org/518093002/diff/120001/runtime/lib/double.dart File runtime/lib/double.dart (right): https://codereview.chromium.org/518093002/diff/120001/runtime/lib/double.dart#newcode140 runtime/lib/double.dart:140: static const int CACHE_LENGTH = 16; How ...
6 years, 3 months ago (2014-08-29 20:58:47 UTC) #3
koda
https://codereview.chromium.org/518093002/diff/120001/runtime/lib/double.dart File runtime/lib/double.dart (right): https://codereview.chromium.org/518093002/diff/120001/runtime/lib/double.dart#newcode140 runtime/lib/double.dart:140: static const int CACHE_LENGTH = 16; On 2014/08/29 20:58:47, ...
6 years, 3 months ago (2014-08-29 21:02:33 UTC) #4
koda
Committed patchset #7 (id:120001) manually as r39710 (presubmit successful).
6 years, 3 months ago (2014-08-29 21:13:36 UTC) #5
Lasse Reichstein Nielsen
6 years, 3 months ago (2014-09-01 07:14:21 UTC) #7
Message was sent while issue was closed.
https://codereview.chromium.org/518093002/diff/120001/runtime/lib/double.dart
File runtime/lib/double.dart (right):

https://codereview.chromium.org/518093002/diff/120001/runtime/lib/double.dart...
runtime/lib/double.dart:144: static int _cacheEvictIndex = 0;
This "optimization" seems a little too speculative to me.
Are there cases, outside of silly benchmarks, where the same four doubles keep
getting toString'ed? If so, is it always the same doubles (e.g., -1.0, 0.0, 1.0,
and 2.0) so we could just hardcode those?

https://codereview.chromium.org/518093002/diff/120001/runtime/lib/integers.dart
File runtime/lib/integers.dart (right):

https://codereview.chromium.org/518093002/diff/120001/runtime/lib/integers.da...
runtime/lib/integers.dart:319: "91", "92", "93", "94", "95", "96", "97", "98",
"99",
There isn't anything inherently wrong with a trailing comma in Dart. I would
actually prefer it for "tables" like this one, because it makes it easier to add
more lines or rearrange lines.
(But this is VM code, so do go with the VM preferred style here).

https://codereview.chromium.org/518093002/diff/120001/runtime/lib/integers.da...
runtime/lib/integers.dart:349: if (this < 100 && this > -100) return
_smallLookupTable[this + 99];
Would it make sense to put this after the sign check?
Then we would have:
  if (this < 0) return _negativeToString(this);
  if (this < 100) return _posSmallLookupTable[this];
and in _negativeToSTring
  if (this > -100) return _negSmallLookupTable[this + 99];

It seems to have one less test for the positive case (but then, -99..99 test can
be done in one compare by a good compiler).
I.e., do we have a benchmark that can see what is best?

Powered by Google App Engine
This is Rietveld 408576698