webpack / webpack/tsc

Replace the Serializer with `node:v8`

Open
#171 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
5
Forks
3
Avg merge
1m
Merged PRs (30d)
1

Description

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.

For example,

class ModuleDependency {
  constructor(request, range) {
    this.request = request;
    this.range = range;
    this.optional = false;
    this.weak = false;
  }
  
  toObject() {
    return {
      request: this.request,
      range: this.range ? [this.range[0], this.range[1]] : null,
      optional: this.optional,
      weak: this.weak
    };
  }
  
  static fromObject(obj) {
    const dependency = new ModuleDependency(obj.request, obj.range);
    dependency.optional = obj.optional;
    dependency.weak = obj.weak;
    return dependency;
  }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating Webpack’s custom serialization mechanism and the cache classes that participate in it. Review Node.js’s v8.serialize and v8.deserialize behavior, then define the stable object representations and reconstruction methods for those classes; done means the cache uses node:v8 without relying on the custom serializer.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
build-system, tooling
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.