Skip to content

Brainstorming Features #2

@WebReflection

Description

@WebReflection

Now that this module is fully covered and production ready, I’d like to write down thoughts around its application and how this can improve further to better tackle all use cases.

Recursion


Update it's in and it works wonderfully


It’s wonderful and super fast but it inevitably retains a lot in memory. This is not really an issue in JS, those references will be kept in memory anyway until the returned reference exists, but it makes lower level serialization (WASM, C, Zig) more convoluted for little benefits when:

  • data is created out of SQLite. It’s true that strings repetition is common, each row key, but it’s also true that there could be thousand different strings or numbers as value … is it worth to track all of them in memory?
  • streamed data. With a pre-defined static buffer it’s all good but with data streamed on demand, which is potentially huge, the amount of RAM needed to track recursion might be huge and not friendly with constrained devices (MicroPython to name a use case). The same goes for decoding such data. If the stream is huge, there is no way to free memory while decoding each part of it until the stream ends.
  • cases where recursion is neither expected nor desired for complex data. With JSON that’s not possible but in the other hand, this is the reason flatted has million downloads per week.

In other libraries recursion is only for non primitives but here there is a chance to fine tune its capabilities:

  • all means recursion for anything as it is now, except Boolean, null and empty strings
  • some could mean only non primitive data
  • none could mean no recursion expected, will eventually throw out of max stack because if anything is retained in memory to track non primitives there is little gain … worth it?

The question is if the implementation should be bitwise based, so that grouping cases or excluding these can be ad hoc, or generic enough which feels more appropriate.

Once generic: should the default be more relaxed (some) or does it matter, since at deciding time, unless is none, it either works or throw if none is expected?

Hooks while encoding

Having a toBufferedClone symbol feels the right thing to do but should I think about a way to also decode the returning value later?

This could be a method passed as option in both encoding and decoding, where the different data could be transformed in and back.

Performance


Update ... conclusions


Need to test:

  • raw JSON comparison - update ✅ done ... and it currently sucks
  • postMessage - update ✅ done, it's up to 100X faster on postMessage over complex data ... and it is currently as fast on single pass, and once hot, but X times faster on multiple pass of the same data around
  • worth writing a native node thing too to see how much this would improve performance if it was a native API?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions