-
Notifications
You must be signed in to change notification settings - Fork 191
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
[perf | trim] Remove extra class #1510
[perf | trim] Remove extra class #1510
Conversation
It seems we don't need to have extra class SingleNodeBounds for 2 cases
How does this affect perf? Is it a memory thing? Or something else? I've been trying to get tracerbench setup, but no success yet |
I think it's likely memory thing, comparing to perf, creating one class instead of 2 in 10000 items is 1% faster. class A {
constructor(a,b,c) {
this.a = a;
this.b = b;
this.c = c;
}
}
class B {
constructor(a,b,c) {
this.a = a;
this.b = b;
this.c = c;
}
}
var items = new Array(10000).fill(null); items.map((e,index) => {
return index % 2 === 0 ? new A(Math.random(), Math.random(), Math.random()) : new B(Math.random(), Math.random(), Math.random());
}); items.map((e,index) => {
return index % 2 === 0 ? new A(Math.random(), Math.random(), Math.random()) : new A(Math.random(), Math.random(), Math.random());
}); |
Hm, impact is even greater on Firefox. Nice find! |
This change itself is fine but this is definitely not a valid way to benchmark this change. Please refrain from making perf changes from microbenchmarks like these alone |
@lifeart @NullVoxPopuli @chancancode I'm sorry, maybe it's too late. But I've analyzed the microbenchmark https://jsben.ch/EZXRT and I think it has some problems.
In the first case, we conditionally create either __appendFragment(fragment: SimpleDocumentFragment): Bounds {
// ...
if (first) {
let ret = new ConcreteBounds(this.element, first, fragment.lastChild!);
// ...
} else {
// ...
return new SingleNodeBounds(this.element, this.__appendComment(''));
}
} In the second case, we always create appendDynamicNode(value: SimpleNode): void {
// ...
let bounds = new SingleNodeBounds(this.element, node);
// ...
} The microbenchmark tries to imitate only the first case, and only when branch chances are 50/50. I have no information about the real-world applications but I doubt that they all have the same chances. Also, the microbenchmark completely ignores the second case. Ideally, @lifeart should have determined amounts of class constructor invocations and typical patterns (e.g.
I've changed the code to be closer to the original classes using the compiled code from Unfortunately, my modified benchmark shows opposite results, i.e. two original classes might be up to 20% faster than a proposed single class Anyway, what I want to say is:
|
Agree. 3-4% in the synthetic benchmark is negligible. |
Yes, as I said in the comment when merging this, the benchmarks are not valid and this is not a place where performance likely would matter. I merged it because the extra class does seem a bit superfluous, used sparingly and didn’t help with readability enough to warrant it existing. But I kept trying to say here and elsewhere, making these kind of changes based on narrow microbenchmarks are no good, and even synthetic benchmarks like js-framework-benchmark is not representative of real world patterns. |
reducing amount of code to maintain is still nice, so that's a win
agreed
big disagree. This is a decision by which folks judge our ecosystem and framework, and at the very least we need to not trip and fall flat on our face <3 thankfully, there is a ton of room for improvement!!! |
It seems we don't need to have extra class SingleNodeBounds for 2 cases