-
Notifications
You must be signed in to change notification settings - Fork 435
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
fix(sanity): optimise getLeafWeights to not stack overflow #7999
fix(sanity): optimise getLeafWeights to not stack overflow #7999
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
@nikaspran is attempting to deploy a commit to the Sanity Sandbox Team on Vercel. A member of the Team first needs to authorize it. |
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.
Looks solid to me. Appreciate you taking the time to add tests as well @nikaspran 🙏🏼
Would love a second pair of eyes from @juice49 as well.
I can confirm this also fixes our actual issue my company's setup, so would love to get this in and unblock 🙏 Happy to make any changes if necessary. |
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 is fantastic! Thank you so much for the contribution, @nikaspran.
* next: (49 commits) fix: delays rendering the Start in Create banner until document is ready (#8020) fix(deps): update dependency @sanity/ui to ^2.10.9 (#8009) chore(deps): dedupe pnpm-lock.yaml (#8023) test(playwright-ct): fix issues and flake (#8016) feat(cli): misc copy changes (#8003) feat(cli): remove is-builtin-module (#6579) v3.67.1 chore(deps): bump minimum requirement of @sanity/import and @sanity/export (#8012) chore(deps): update dependency @sanity/pkg-utils to v6.12.0 (#8010) fix(core): tasks UpdatedTimeAgo should be a hook (#8011) v3.67.0 chore(prettier): fix unformatted files 🤖 ✨ (#8006) chore: reduce renovate double PR noise fix(deps): update dependency @sanity/ui to ^2.10.7 (#8005) fix(deps): update dependency @sanity/ui to ^2.10.7 (#7998) feat(cli): use `@vercel/frameworks` in `bootstrapRemoteTemplate` (#8001) feat: switch create integration to opt-out flow (#8002) feat: use eslint 9 for new studios (#7978) fix(sanity): optimise getLeafWeights to not stack overflow (#7999) feat(test-studio): enable `groq2024` search strategy ...
Description
When working on schemas that branch out a lot (i.e. have arrays that can hold many different types), the current
getLeafWeights
implementation throws with aRangeError: Maximum call stack size exceeded
after a while.This PR optimises the method to use an accumulator instead, which keeps the stack usage flat and no longer overflows for the same amount of data. I have also added a test to verify this (it used to explode with the previous version, see screenshots).
In addition, this PR optimises the method to be much more efficient by:
objectTypes
andarrayTypes
into oneAs a result, this should be much faster and no longer explode the stack.
Before
After
What to review
Testing
Notes for release
Fixes a crash when rendering a document list within Studio given a schema that branches out a lot