Frank Rollpin
2016-05-04 20:20:26 UTC
Hi, I am running a computationally-intensive web application in regular
Chrome (built by dart2js), and noticed that on many occasions, certain
routines are 2-10 times slower in JavaScript, compared to the Dart version.
Further investigation traced some of the difference to the way operators
are (not) inlined in JavaScript. At least this is how it appears to me. In
the code below, both methods (testSetOperator and testInlinedSet) are
equally fast under Dart VM (65ms), then there is an expected 25% penalty
when testInlinedSet is executed in JavaScript, but JavaScript's
testSetOperator is more than 3 times slower.
Not sure if this is a bug? Will it be addressed in the later versions of
dart2js? Is there an alternative way to write this code to make the
inlining happen, or force it?
On a similar subject, are there any guidelines, recommendations, or any
other resources related to the Dart performance, especially related to the
performance of the JavaScript code?
Environment:
Dart SDK 1.15
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/50.0.2661.94 Safari/537.36
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/45.0.2454.0 (Dart) Safari/537.36
Windows x64
class BitSetPerfTest {
static const int size = 1000000;
Uint32List _data = new Uint32List(size);
bool operator [] (int pos) => ((_data[pos ~/ 0x20] & (1 << (pos & 0x1f)))
!= 0);
void operator []= (int pos, bool value) {
if (value)
_data[pos ~/ 0x20] |= 1 << (pos & 0x1f);
else
_data[pos ~/ 0x20] &= ~(1 << (pos & 0x1f));
}
// 257ms
void testSetOperator() {
for (int n = 0; n < 10; n++)
for (int i = 0; i < size; i++)
this[i] = i % 2 == 0;
}
// 81 ms
void testInlinedSet() {
for (int n = 0; n < 10; n++)
for (int i = 0; i < size; i++) {
bool v = i % 2 == 0;
if (v)
_data[i ~/ 0x20] |= 1 << (i & 0x1f);
else
_data[i ~/ 0x20] &= ~(1 << (i & 0x1f));
}
}
}
Chrome (built by dart2js), and noticed that on many occasions, certain
routines are 2-10 times slower in JavaScript, compared to the Dart version.
Further investigation traced some of the difference to the way operators
are (not) inlined in JavaScript. At least this is how it appears to me. In
the code below, both methods (testSetOperator and testInlinedSet) are
equally fast under Dart VM (65ms), then there is an expected 25% penalty
when testInlinedSet is executed in JavaScript, but JavaScript's
testSetOperator is more than 3 times slower.
Not sure if this is a bug? Will it be addressed in the later versions of
dart2js? Is there an alternative way to write this code to make the
inlining happen, or force it?
On a similar subject, are there any guidelines, recommendations, or any
other resources related to the Dart performance, especially related to the
performance of the JavaScript code?
Environment:
Dart SDK 1.15
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/50.0.2661.94 Safari/537.36
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/45.0.2454.0 (Dart) Safari/537.36
Windows x64
class BitSetPerfTest {
static const int size = 1000000;
Uint32List _data = new Uint32List(size);
bool operator [] (int pos) => ((_data[pos ~/ 0x20] & (1 << (pos & 0x1f)))
!= 0);
void operator []= (int pos, bool value) {
if (value)
_data[pos ~/ 0x20] |= 1 << (pos & 0x1f);
else
_data[pos ~/ 0x20] &= ~(1 << (pos & 0x1f));
}
// 257ms
void testSetOperator() {
for (int n = 0; n < 10; n++)
for (int i = 0; i < size; i++)
this[i] = i % 2 == 0;
}
// 81 ms
void testInlinedSet() {
for (int n = 0; n < 10; n++)
for (int i = 0; i < size; i++) {
bool v = i % 2 == 0;
if (v)
_data[i ~/ 0x20] |= 1 << (i & 0x1f);
else
_data[i ~/ 0x20] &= ~(1 << (i & 0x1f));
}
}
}
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.