You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, Webpack implements a custom serialization mechanism for its caching system. This requires maintaining complex serialization logic and keeping it updated as JavaScript features evolve.
Instead of relying on a custom serializer, we can delegate object encoding/decoding to Node.js's built-in v8.serialize and v8.deserialize.
For this approach to work, all Webpack-internal classes participating in the cache must define a stable object representation.
For a class to be Serializable:
It must implement an instance method:
toObject()->Object// Note: Classes _can_ be serialized directly, but they will be converted to Objects by V8
Produces a plain object representation safe to pass into the serializer.
It must implement a static method:
fromObject(obj: Object)->Instance
Reconstructs the class instance from the serialized representation.
@avivkeller Just wonder, why you get toObject and fromObject names? Any reference for it? For me serialize and deserialize are more clear... I tried using v8, looks like we can implement it, but need refactor
Activity
alexander-akait commentedon Aug 15, 2025
Do you profile it deeply? Where do we waste the most time?
avivkeller commentedon Aug 15, 2025
Benchmark
(
.processonObjectMiddlewareis the slowest path)avivkeller commentedon Aug 15, 2025
Serialization is only used for hashing, right? @ovflowd were trying to figure out where else it was used during our meeting
avivkeller commentedon Aug 16, 2025
I'm sure there's a dependency that might be able to cut down on this custom code (msgpack?)
alexander-akait commentedon Aug 17, 2025
For caching
Maybe when we wrote this, there were no ready-made solutions at all
[-]Speed Up (and Document) the Serializer[/-][+]Replace the Serializer with `msgpack`[/+][-]Replace the Serializer with `msgpack`[/-][+]Replace the Serializer with dep[/+]avivkeller commentedon Aug 17, 2025
It would definitely be nice to replace this with a dependency. Running the same benchmark with a few other libraries:
node:v8: ~38 secondscbor-x: ~44 seconds[-]Replace the Serializer with dep[/-][+]Replace the Serializer with `node:v8`[/+]ovflowd commentedon Aug 18, 2025
That seems an accurate statement lol
alexander-akait commentedon Nov 26, 2025
@avivkeller Just wonder, why you get
toObjectandfromObjectnames? Any reference for it? For meserializeanddeserializeare more clear... I tried usingv8, looks like we can implement it, but need refactor