Skip to content

Make serialization up to 5x faster for nested resources

Latest

Choose a tag to compare

@github-actions github-actions released this 03 Nov 22:36
Immutable release. Only release title and notes can be modified.

2.3.2

This release makes serialization much faster, especially for responses with nested relations. The serialized output does not change.

Nested serialization is ~5x faster (#10)

transform() and paginate() used to create a RuntimeException on every call. Its only purpose was to give a useful stack trace when a transformer receives undefined. Capturing a stack trace is expensive (~3 µs per call), and with one call per row and per relation, it was ~72% of the CPU time on a paginated response with nested relations.

The error is now created only when the value is undefined. It is still created at the same call site, so the stack trace still points to your transformer.

Workload Before After
Paginated, 20 users with profile, posts and comments (840 transformers) 1481.5 µs 275.7 µs (5.4× faster)
Single item with relations (42 transformers) 77.6 µs 14.6 µs (5.3× faster)

The debuggingError argument of the Item and Collection constructors is now optional. Existing calls keep working. An Item created without it now throws the expected "Cannot transform undefined value" error, where it used to throw a TypeError.

Flat lists serialize ~20% faster (#9)

resolveValues no longer awaits an empty list of promises. This saves one async suspension per transformer that has no relation to resolve, such as flat rows and leaf resources. A list of 500 rows went from 619 µs to 492 µs.

As a side effect, a .then() callback on the result of a leaf transformer now runs one microtask earlier.

Performance Improvements

  • make nested serialization 5x faster by skipping stack captures (613cb06)
  • skip awaiting empty promise list in resolveValues (c2b4144)

Chores

  • correct the documentation of the omit method by @FlorianV85 in #7
  • harden the release workflow for supply-chain security (#6)
  • update dependencies

New Contributors

Full Changelog: v2.3.1...v2.3.2