-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
chore: add retrieveSchema
at Form
state to memoize the result of schemUtils.retrieveSchema
#3970
Conversation
I'm facing issues to run lerna, that's hanging. @heath-freenome or @zxbodya can you help me? Versions OS: macOS 13.4.1 - m1 pro |
Do the other commands (i.e. |
No, they don't. The script for each package works ok, but from lerna doesn't. |
Related to: #1961 (comment) |
@heath-freenome using npx i got a better info, the issue seems be related to Nx. Then i removed the nx.json and entry from lerna.json and everything worked well. |
if (omitExtraData === true && liveOmit === true) { | ||
const retrievedSchema = schemaUtils.retrieveSchema(schema, formData); | ||
const pathSchema = schemaUtils.toPathSchema(retrievedSchema, '', formData); | ||
_retrievedSchema = schemaUtils.retrieveSchema(schema, formData); |
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.
Would this work if you declared the newState
object outside of its current conditional block?
_retrievedSchema = schemaUtils.retrieveSchema(schema, formData); | |
_retrievedSchema = newState?.retrievedSchema ?? schemaUtils.retrieveSchema(schema, formData); |
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.
When I run the test, it fails on some tests with {"omitExtraData":true,"liveOmit":true}
. Not fully sure, but probably, because the schema is old with unnecessary properties. 4 tests failed
Reasons for making this change
This PR focus on improve the onChange performance avoiding recalculate the
retrievedSchema
multiples times when Form hasliveValidate
prop true.Before:
At the image below from a profiling of a keystroke on a field, the onChange function call retrieveSchema 2 and one more time during the update of the form component is, at getSnapshotBeforeUpdate. The time of
onChange
(~260ms) +getSnapshotBeforeUpdate
(~166ms) represents 65% of task duration (~685ms)After:
As you can see at the profiling below, the
retrieveSchema
function isn't called atonChange
andgetSnapshotBeforeUpdate
. The result is, the onChange took ~100ms and the getSnapshotBeforeUpdate took ~87ms, this represents ~28% of the task duration ~652ms.This PR follows the same idea from this one #3959
If your PR is non-trivial and you'd like to schedule a synchronous review, please add it to the weekly meeting agenda: https://docs.google.com/document/d/12PjTvv21k6LIky6bNQVnsplMLLnmEuypTLQF8a-8Wss/edit
Checklist
npm run test:update
to update snapshots, if needed.