Skip to content
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

Object creation benchmark #8

Closed
mcollina opened this issue Jul 28, 2017 · 7 comments
Closed

Object creation benchmark #8

mcollina opened this issue Jul 28, 2017 · 7 comments

Comments

@mcollina
Copy link
Collaborator

mcollina commented Jul 28, 2017

@hashseed thanks so much for in-depth review and fixes:

in nodejs/CTC#155 (comment) you wrote:

Object creation benchmarks don't actually create the objects because TF optimized it away. Again, with my changes, the benchmark results are more useful:

Node.js v8.2.1 with V8 5.8:

literal x 28,455,810 ops/sec ±1.19% (83 runs sampled)
class x 21,993,317 ops/sec ±1.13% (86 runs sampled)
constructor x 28,093,899 ops/sec ±0.73% (82 runs sampled)

Node.js v9.0.0-v8-canary20170724c045f1f8dc with V8 6.2.4:

literal x 31,861,977 ops/sec ±0.88% (86 runs sampled)
class x 32,265,246 ops/sec ±0.65% (90 runs sampled)
constructor x 32,120,661 ops/sec ±0.99% (87 runs sampled)

When is this optimization happening? I've tried https://gist.github.com/mcollina/b903a1ef99f872ceb8e51dc491be34b8 (accessing a property) and https://gist.github.com/mcollina/40e91ad55ae9c3b0131c2a8b79387dfe (passing an object to a function), and it leads to similar previous results compared to the previous benchmark. However https://gist.github.com/mcollina/0bbcca999f7c190d97009165b7913824 reduces the gap.

It seems that if the object has hardcoded properties, then Turbofan can optimize the object creation away. I think this is a change worth including in our report, as passing objects with hardcoded properties as an "option object" is a widely used pattern.

I would like to keep including the previous benchmark (or one of above) and rebrand it as "option objects", to document this new behavior which in my opinion it is a fantastic result.
Which benchmark do you think fit better the case?

cc @bmeurer @TimothyGu

@mcollina mcollina changed the title Object creation benchmarks Object creation benchmark Jul 28, 2017
@TimothyGu
Copy link
Contributor

To be clear, the fact that the object creation benchmark doesn't test object creation was actually discovered by Jakob Kummerow of the V8 project in a comment to the blog post, and it was I who wrote the fix and nodejs/CTC#155 (comment) you linked above. I'm not sure if he is on GitHub though.

Speaking of that, it seems like there was some merge conflicts: https://github.com/davidmarkclements/v8-perf/blob/master/bench/object-creation.js now again contains a var obj

@mcollina
Copy link
Collaborator Author

Speaking of that, it seems like there was some merge conflicts: https://github.com/davidmarkclements/v8-perf/blob/master/bench/object-creation.js now again contains a var obj…

It seems Object.create() is not optimized away. I will remove the var anyway for parity.

@jakobkummerow
Copy link

+1 to @TimothyGu 's changes. The new results look plausible.

Turbofan can optimize the object creation away

Crankshaft could do that too, under the right circumstances ;-)

@davidmarkclements
Copy link
Owner

the Object.create bench isn't equivalent - it's creating a object with a prototype of { x: 1 }

either we have to set this with define properties config object or by adding a prop

@davidmarkclements
Copy link
Owner

hey @jakobkummerow - which circumstances can trigger this object inlining behaviour in Crankshaft?

@jakobkummerow
Copy link

which circumstances can trigger this object inlining behaviour in Crankshaft?

Probably mostly the circumstances in the Octane benchmark ;-)
Frankly I'm surprised that the first version of your benchmark didn't seem to trigger the optimization in Crankshaft. I don't have time today to compile an old version and play with it though.

@mcollina
Copy link
Collaborator Author

mcollina commented Aug 3, 2017

Fixed in #17.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants