Skip to content

[9.4] fix(zod): adopt upstream lazy-bind memory optimization (colinhacks/zod#5897) (#266343)#266401

Merged
gsoldevila merged 4 commits intoelastic:9.4from
gsoldevila:backport/9.4/pr-266343
Apr 29, 2026
Merged

[9.4] fix(zod): adopt upstream lazy-bind memory optimization (colinhacks/zod#5897) (#266343)#266401
gsoldevila merged 4 commits intoelastic:9.4from
gsoldevila:backport/9.4/pr-266343

Conversation

@gsoldevila
Copy link
Copy Markdown
Member

Backport

This will backport the following commits from main to 9.4:

Questions ?

Please refer to the Backport tool documentation

Made with Cursor

Replaces `Object.assign(proto, methods)` in the `_initProto` helper
(added by the previous shadow-proto patch) with a `Object.defineProperty`
getter loop:

  for (const [k, fn] of Object.entries(methods)) {
    Object.defineProperty(proto, k, {
      get() { return fn.bind(this); },
      configurable: true,
      enumerable: false,
    });
  }

When a method is accessed on an instance (e.g. `schema.optional`), the
getter returns a copy bound to `this`, so detached calls — including
destructuring and variable extraction — continue to work:

  const opt = schema.optional;
  opt();  // previously threw; now works correctly

The memory benefits of the shadow-proto approach are fully preserved:
builder methods are still not own properties, so V8 keeps schema
instances in fast-property mode.

Adds a behavioural unit test in `@kbn/zod` that covers the main
detached-call scenarios and documents the known trade-off (each getter
access allocates a new bound function).

Made-with: Cursor
@gsoldevila gsoldevila added backport This PR is a backport of another PR Team:Core Platform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t// release_note:skip Skip the PR/issue when compiling release notes labels Apr 29, 2026
@infra-vault-gh-plugin-prod
Copy link
Copy Markdown

Pinging @elastic/kibana-core (Team:Core)

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

Caution

Review failed

An error occurred during the review process. Please try again later.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • 🛠️ Update Documentation: Commit on current branch
  • 🛠️ Update Documentation: Create PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gsoldevila gsoldevila added ci:build-cloud-image and removed Team:Core Platform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t// release_note:skip Skip the PR/issue when compiling release notes labels Apr 29, 2026
@gsoldevila
Copy link
Copy Markdown
Member Author

/ci

@gsoldevila gsoldevila enabled auto-merge (squash) April 29, 2026 16:36
@kibanamachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
stackConnectors 1.7MB 1.7MB -12.0B
workflowsManagement 2.3MB 2.3MB -12.0B
total -24.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
kbnUiSharedDeps-npmDll 7.3MB 7.3MB -2.5KB

History

@gsoldevila gsoldevila merged commit 495d2c4 into elastic:9.4 Apr 29, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR ci:build-cloud-image

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants