-
Notifications
You must be signed in to change notification settings - Fork 143
Gather and publish CSS Typed OM performance data in an explainer? #634
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
Comments
I've done some initial benchmarking. tl;dr Allocating Typed OM objects is slow, so you have to reuse objects for performance gains. The first benchmark just calls The second benchmark tests a common use case: getting a value from the style map, modifying it, and then putting it back. Here, strings is slightly faster. I suspect this is because we create a new object every time we call [1] On my Chrome Canary (66) build, I get:
[2] I got:
|
Hey @dbaron , I was wondering if you know what sort of performance gains the initial Firefox implementation of Typed OM got? |
I don't have any hands-on experience with the API to say if that makes for a good API or not, but hasten to point out that this would be observable, and so defined by the spec if it isn't already. It's a bit like |
I don't think anybody had an initial impl on Firefox (only typed custom props were implemented, typed om is https://bugzilla.mozilla.org/show_bug.cgi?id=1278697 which doesn't have any patch or similar). In any case probably @jyc knows better than I :) |
This is expected, yeah. The fast case is indeed something like "build a CSSTransformValue, use it in multiple This is why I really really really want ECMAScript to give us Value Objects, or Typed Objects as the proposal seems to have evolved into, where they're just wrappers around a chunk of TypedArray data. These should be much faster because they're immutable and we can reuse them more widely. (This is also why TypedOM was originally as strongly immutable as we could make it with normal JS objects, so we could replace it with Typed Objects later with minimal breakage. We gave up on this when JS appeared to not be willing to give us the thing in a reasonable timescale; we might have to re-evaluate that.) |
After some improvements to performance of StylePropertyMap.get, the results for the roundtripping benchmark that I'm getting are:
Whilst The results were obtained on the new MacBook Pro. On my Linux workstation and my old MacBook Pro, the difference is greater and more consistent: e.g. on my Linux workstation:
Note: The numbers seem to vary a bit, so the relative difference between the two results is probably more useful than their absolute values. |
Also, Blink uses a character-level "fast path" parser for common CSS values like lengths, but not for more complicated ones. So there are many cases where we can't use the fast path, and Typed OM would be significantly faster (you can try it by putting a space after "px" to not go through the fast path). |
This issue (even closed) will capture the discussion so closing it as part of issue triaging. |
In particular, my numbers on the "fast path" show an ~30% increase in ops/sec for TypedOM, agreeing with yours, and on the slow path (using
|
Why immutable objects? Immutable patterns are widely known to be slower than mutable patterns, and immutable patterns are known to be a developer experience benefit over a performance benefit. What am I missing in this case? |
It's entirely dependent on what you're doing with them. Immutable objects allow sharing, so you have lower memory pressure and less computation involved in construction. In return, when you do mutate a structure you have to reconstruct parts of it, which can be slower than just doing an in-place mutation. Which of these factors wins in any given scenario depends on your workload. |
Originally raised by @slightlyoff here: w3ctag/design-reviews#223 (comment)
The text was updated successfully, but these errors were encountered: