swc icon indicating copy to clipboard operation
swc copied to clipboard

perf(plugin): `hstr::Atom` has very inefficient serialization/deserialization logic

Open kdy1 opened this issue 1 month ago • 3 comments

Currently, it creates a String each time it's serialized, but rkyv supports shared-pointer string serializarion.

https://github.com/swc-project/swc/blob/6c68a1e96b1b0ee7a263be94242937c1eec2a729/crates/hstr/src/lib.rs#L387-L418

kdy1 avatar Oct 30 '25 04:10 kdy1

cc @quininer

Regarding https://github.com/swc-project/swc/pull/11100 and https://github.com/swc-project/swc/pull/11198, does this still apply after merging those PRs?

i.e. Does the new serilalization format support a shared-pointer string serialization?

kdy1 avatar Oct 30 '25 04:10 kdy1

No, CBOR doesn't support this; it's just like JSON but in binary format.

If we are to support this, it would look better to use an external string pool and a string ID.

quininer avatar Oct 30 '25 04:10 quininer

String pool sounds good. I'll keep this PR open. I have implemented one for turbopack, so it's not a hard task for me.

kdy1 avatar Oct 30 '25 06:10 kdy1