Optimization: Move the main state machine code into a separate function.
This allows V8 to optimize better, since the separated function doesn't
contain a try-catch.
BUG=None
TEST=None
Note: this diff is against the patch series: https://codereview.appspot.com/7761043 I get about a 36% speedup ...
13 years, 2 months ago
(2013-03-18 20:34:41 UTC)
#1
Note: this diff is against the patch series:
https://codereview.appspot.com/7761043
I get about a 36% speedup on my computer. The difference should be
greater for generators that do more work, or that are longer-lived
(minimizing the creation costs).
#--cut--
dl_check() {
local f=$(basename $1)
test -e $f || curl -sO $1
openssl sha1 < $f | grep -q "= $2" && return 0
echo sha1 mismatch!
return 1
}
git checkout -b issue7759049-yield-expr-8-opt-func-try-catch
cat > bench-gen.js <<"END"
require('./src/node/traceur.js');
function* G(n) {
for (var i = 0; i < n; i++) {
yield i;
}
}
// Don't include generator creation overhead.
var g = G(10000000);
var v = 0;
start = Date.now();
for (var x of g) {
v = (v + x) % 0x40000000;
}
console.log(Date.now() - start, v);
END
### before
./traceur --out bench-gen.out.js -- bench-gen.js && node bench-gen.out.js
dl_check https://codereview.appspot.com/download/issue7759049_2002.diff \
e36a4a8d96d6759c && git apply issue7759049_2002.diff && make test
### after
./traceur --out bench-gen.out.js -- bench-gen.js && node bench-gen.out.js
#--cut--
----
Kind of an aside, but it might be nice to eventually have a series of
standard benchmarks to be able to measure performance regressions or
advancements.
I really like this change. It is nice to extract part of the complications to ...
13 years, 2 months ago
(2013-03-18 21:34:36 UTC)
#3
I really like this change. It is nice to extract part of the complications to a
shared function. It makes things easier to follow and reduces the amount of code
per generator.
Experimenting with patch set series. Git and rietveld were made for each other. There doesn't ...
13 years, 2 months ago
(2013-03-19 19:39:23 UTC)
#4
Experimenting with patch set series. Git and rietveld were made for each
other.
There doesn't seem to be an easy way to scroll through a series of patch
sets, though tabbed browsing can approximate the experience with a
little more clicking.
----
On 2013/03/18 21:34:36, arv-chromium wrote:
> I really like this change. It is nice to extract part of the
> complications to a shared function. It makes things easier to follow
> and reduces the amount of code per generator.
After having worked with this code awhile (especially on some upcoming
patches for optimizing the state machine output) I can't help thinking
that making some even larger architectural divisions would make this
code even more understandable.
One of the biggest things is that
- the transformer(s) for creating the state machine, and
- the code for generating the code from that state machine
are mixed together in GeneratorTransformer and CPSTransformer.
Another is that a lot of the utility functions for
- transforming state machines, or
- transforming or querying combinations of state machines and normal
ParseTree nodes
are private members of CPSTransformer, when they don't need to be.
I still have a few patches in flight, so it's not convenient to do any
of these at the moment, but just noting them for future reference.
The biggest win in clarity would come from more dramatic changes,
which would be even further in the future. The biggest driver for this
would be if it makes it easier to do state machine optimizations, or
to integrate full yield expressions.
https://codereview.appspot.com/7759049/diff/21001/src/runtime/runtime.js
File src/runtime/runtime.js (right):
https://codereview.appspot.com/7759049/diff/21001/src/runtime/runtime.js#newc...
src/runtime/runtime.js:329: return object;
One of those cases where it's nice to be able to modify the runtime api.
https://codereview.appspot.com/7759049/diff/25001/src/codegeneration/generato...
File src/codegeneration/generator/AsyncTransformer.js (right):
https://codereview.appspot.com/7759049/diff/25001/src/codegeneration/generato...
src/codegeneration/generator/AsyncTransformer.js:267: var ${id(CONTINUATION)} =
${id(G)}.moveNext.bind(${id(G)});`);
Obviously, there are a lot of complicated ParseTreeFactory calls here
that could be converted to use parseStatement. I'm reluctant to clean up
this file too much, since 'async' is probably not going to be in the
spec, which means that this file is likely going away sometime.
For the moment, I've just decided to do the minimum necessary to pass
the current set of async tests.
Issue 7759049: Optimization: Move the main state machine code into a separate function.
(Closed)
Created 13 years, 3 months ago by usrbincc
Modified 13 years, 2 months ago
Reviewers: arv, slightlylate, peterhal
Base URL: https://code.google.com/p/traceur-compiler/@master
Comments: 6