Skip to content

Conversation

@yangskyboxlabs
Copy link

Allow Assembler customizations to replace Object instances with Map without affecting the rest of its functionality. It makes it much more efficient when deserializing large "objects" that are functionally lookup tables, with minimal customization.

The mechanism for determining when replacement with Map is used is out-of-scope. There are no new APIs added.


I have a use case where the parsed JSON consists primarily of large lookup tables (700+ entries per table):

{
  "modules": {
    "mod000": { /*...*/ },
    "mod001": { /*...*/ },
    //...
    "mod750": { /*...*/ }
  },
  "metadata": { /*...*/ }
}

The table is transformed to Map for actual usage, which is a somewhat awkward process. With Assembler modified to understand Map, it becomes much simpler.

class ModuleTableAssembler extends Assembler {
  startObject() {
    super.startObject()
    if (useMap(this.stack)) {
      this.current = new Map();
    }
  }
}

const asm = new ModuleTableAssembler();
for await (const token of parser.iterator()) {
  asm.consume(token);
}
const moduleTable = asm.current;

Doing this with monkey patching is possible but very awkward due to the way Assembler's internal methods are connected. Extending _saveValue() to cover Map makes this basically trivial..

Allow Assembler customizations to replace Object instances with Map
without affecting the rest of its functionality.  It makes it much more
efficient when deserializing large "objects" that are functionally
lookup tables, with minimal customization.

The mechanism for determining when replacement with Map is used is
out-of-scope.  There are no new APIs added.
@uhop uhop self-assigned this Oct 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants