Open josephrocca opened 1 year ago
Interesting. I would suspect V8 to be honest, but is there a reason you aren't using arrays and join?
I'm not sure why (just V8 optimization-fu, I guess?), but if this is what you meant:
let chunks = [];
for(let key in obj) {
chunks.push(`${key}: ${obj[key]}`);
}
let str = chunks.join("\n");
that does indeed get significantly closer to matching Bun performance. For Bun, the previous "string append" approach is about 10% faster than the above array version.
Fastest Bun:
time to make obj: 73.572666
time to make str: 4352.123359 ("string append" approach)
Fastest Deno:
time to make obj: 1102
time to make str: 5240 ("array join" approach)
While investigating a problem on one of my production servers (where, in case you're curious, an operation wasn't completing in time after a SIGINT, resulting in a SIGKILL by
pm2
), I eventually ended up with this micro-benchmark:Bun is ~10x faster at making
obj
, and ~1.5x faster at makingstr
. If I changeMath.random()
to"aaaaaaaaaaaaaa"
, then Bun is only ~5x faster at makingobj
.I also tried
"aaaaaaaaaaaaaa😊"
in case it was somehow related to (lack of) Latin-1 optimizations, but that didn't affect the scores.In Chrome (I only tested v118), making
obj
is ~10x slower, but makingstr
is about the same speed as in Bun, weirdly.This isn't a huge deal for me (unlike #20409 and #20428 and especially #20355), so I don't want to risk drawing dev hours away from more important things, but it is an actual issue I had in production, so I figured it'd be a shame not to share it.
Please close if this is better filed on crbug.