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
dart2js produces bailout-heavy code for simple example of requestAnimationFrame #10071
Comments
See also https://groups.google.com/a/dartlang.org/forum/?fromgroups=#!topic/compiler-dev/SOcapH1LPPc for discussion. |
One suggestion is to rewrite to: import 'dart:html'; class Looper { var loop; // Cached closure to pass to rAF. Looper() { void kick() { _loop(currentTime) { if (_renderTime == 0) if (_renderTime > currentTime) double deltaTime = currentTime - _renderTime; if (deltaTime >= 1) { void main() { |
Added C3 label. |
Added this to the Later milestone. |
Added TriageForM5 label. |
Removed TriageForM5 label. |
Removed this from the Later milestone. |
Removed Oldschool-Milestone-Later label. |
I think this is fixed, unless I'm running dart2js differently. Lines reduced from 21 to 16: $ cat issue-10071.dart double _renderTime = 0; loop(final num currentTime) { if (_renderTime == 0) if (_renderTime > currentTime) double deltaTime = currentTime - _renderTime; if (deltaTime >= 1) { void main() { $ dart2js issue-10071.dart $ grep -A 16 'loop:' out.js Only 2 check/bailout pairs, down from 4. |
But it uses non-typed interceptor methods. |
Consider this code:
import 'dart:html';
double _renderTime = 0;
loop(final num currentTime) {
window.requestAnimationFrame(loop);
if (_renderTime == 0)
_renderTime = currentTime;
if (_renderTime > currentTime)
_renderTime = currentTime;
double deltaTime = currentTime - _renderTime;
double deltaTimeSec = deltaTime / 1000.0;
double currentTimeSec = currentTime / 1000.0;
if (deltaTime >= 1) {
_renderTime = currentTime;
}
}
void main() {
window.requestAnimationFrame(loop);
}
Here's the generated code:
$.loop = function(currentTime) {
var t1;
if (typeof currentTime !== "number")
return $.loop$bailout(1, currentTime);
$.requestAnimationFrame$1$x(window, $.loop);
t1 = $._renderTime;
if (typeof t1 !== "number")
return $.loop$bailout(2, currentTime, t1);
if (t1 === 0)
$._renderTime = currentTime;
t1 = $._renderTime;
if (typeof t1 !== "number")
return $.loop$bailout(3, currentTime, t1);
if (t1 > currentTime)
$._renderTime = currentTime;
t1 = $._renderTime;
if (typeof t1 !== "number")
return $.loop$bailout(4, currentTime, t1);
if (currentTime - t1 >= 1)
$._renderTime = currentTime;
};
Can we reduce the generated checks and bailouts?
The text was updated successfully, but these errors were encountered: