Skip to content

perf(core): match serializer fields and populate paths by first segment - #8464

Open
vkouk wants to merge 1 commit into
mikro-orm:masterfrom
vkouk:perf/serializer-fields-lookup
Open

vkouk wants to merge 1 commit into
mikro-orm:masterfrom
vkouk:perf/serializer-fields-lookup

Conversation

@vkouk

@vkouk vkouk commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

isVisible and isPopulated scanned the whole fields/populate list for every property of every entity, and child options were rebuilt for each relation of each entity. With a fields whitelist that cost grows with properties times fields.

serialize() now copies the caller options once per call, so the first-segment lookups and the derived child options are cached for every entity of that call. The caller's options are no longer mutated (populate used to be normalized to an array in place).

Serializing 500 entities with a 40-path fields whitelist: 15.1 -> 12.3 ms median. Populate-only and narrow fields are unchanged.

`isVisible` and `isPopulated` scanned the whole `fields`/`populate` list for every property of every
entity, and child options were rebuilt for each relation of each entity. With a `fields` whitelist
that cost grows with properties times fields.

`serialize()` now copies the caller options once per call, so the first-segment lookups and the
derived child options are cached for every entity of that call. The caller's options are no longer
mutated (`populate` used to be normalized to an array in place).

Serializing 500 entities with a 40-path `fields` whitelist: 15.1 -> 12.3 ms median. Populate-only
and narrow `fields` are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.65%. Comparing base (690e734) to head (99f52d1).

Files with missing lines Patch % Lines
...ackages/core/src/serialization/EntitySerializer.ts 93.33% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8464      +/-   ##
==========================================
- Coverage   99.66%   99.65%   -0.01%     
==========================================
  Files         293      293              
  Lines       32172    32206      +34     
  Branches     9268     9275       +7     
==========================================
+ Hits        32065    32096      +31     
- Misses        103      106       +3     
  Partials        4        4              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
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