-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Security Solution] Make kbn-openapi-generator producing lazy loaded Zod schemas #264125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jbudz
merged 13 commits into
elastic:main
from
maximpn:reduce-baseline-memory-consumption
Apr 22, 2026
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
bd5f88a
migrate from zod.merge to zod.extend
maximpn ec2c0ff
avoid exporting schemas
maximpn 1620468
load Zod schemas lazily
maximpn f59304f
use WeakMap to make Zod schemas GCable
maximpn 68ed769
extract generic lazyGCableObject utility function
maximpn 6bc2d79
make lazy object immutability explicitly clear
maximpn cc750e9
support for...in loops and spread operators
maximpn b73187e
disallow usage of defineProperty in lazySchema
maximpn 06391dc
increase securitySolution page load bundle size limit
maximpn b09f8c4
address the feedback
maximpn 131236d
allow disabling lazy schemas via disableLazyZodSchemas feature flag
maximpn eef640d
remove @kbn/lazy-object dependency
maximpn e8cdbef
Merge remote-tracking branch 'upstream/main' into reduce-baseline-mem…
maximpn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI generated the detailed description. It looks useful so I'll keep it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,40 @@ | ||
| # @kbn/lazy-object | ||
|
|
||
| Empty package generated by @kbn/generate | ||
| Utilities for deferring the construction of objects until they are first used, | ||
| so that modules that declare many objects at load-time don't pay the | ||
| construction cost (time and memory) for the ones that are never touched. | ||
|
|
||
| The package offers several variants that differ in granularity, caching, and | ||
| how they're authored: | ||
|
|
||
| ## `lazyObject(obj)` + Babel plugin | ||
|
|
||
| Author object literals normally; a Babel plugin rewrites `lazyObject({ ... })` | ||
| call sites into `createLazyObjectFromFactories({ key: () => expr, ... })` so | ||
| each property is built on first access and cached forever. At runtime without | ||
| the Babel plugin this is an identity function. | ||
|
|
||
| Use when: you want ergonomic lazy fields on an object without changing source | ||
| style. Requires the Babel plugin in the build. | ||
|
|
||
| ## `createLazyObjectFromFactories(factories)` | ||
|
|
||
| Runtime-only version of the above. Takes an object whose values are factory | ||
| functions and returns an object whose properties materialize on first read | ||
| (cached forever). No build-time support needed. | ||
|
|
||
| Use when: you want per-property laziness without the Babel plugin. | ||
|
|
||
| ## `createLazyObjectFromAnnotations(obj)` + `annotateLazy(fn)` | ||
|
|
||
| Like `createLazyObjectFromFactories`, but you mark individual factory values | ||
| with `annotateLazy(...)` so an object can mix eagerly-defined fields with | ||
| lazily-computed ones. | ||
|
|
||
| Use when: only some fields of an object benefit from laziness. | ||
|
|
||
| ## Metrics | ||
|
|
||
| `getLazyObjectMetrics()` returns a `{ count, called }` snapshot for the | ||
| annotation-based variants (how many lazy keys were registered vs. materialized), | ||
| useful when evaluating whether laziness is paying off in a given module graph. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new limit far exceeds the current count as per the latest build, which is 153.5KB. Should we choose a more conservative value here, or perhaps even keep the current limit as the change doesn't seem needed?