Skip to content
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

perf: optimize traversals with a very large number of errors #1172

Merged
merged 5 commits into from
Oct 12, 2024

Conversation

Dimava
Copy link
Contributor

@Dimava Dimava commented Oct 11, 2024

No description provided.

@Dimava
Copy link
Contributor Author

Dimava commented Oct 11, 2024

Possibly I forgot the this.errors.byPath[""] check

Copy link
Member

@ssalbdivad ssalbdivad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not optimized enough for an optimization PR

const propString = pathToPropString(path)
return this.errors.some(e => propString.startsWith(e.propString))
for (let i = 0; i <= path.length; i++) {
const partialPropString = pathToPropString(path.slice(0, i))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pathToPropString already has to iterate the path. Look at that logic and reuse the internal methods so build it here as you go so this isn't n^2

@ssalbdivad ssalbdivad changed the title fix performance regression on large amount of errors perf: optimize traversals with a very large number of errors Oct 12, 2024
const propString = pathToPropString(path)
return this.errors.some(e => propString.startsWith(e.propString))
let partialPropString: string = ""
if (Object.hasOwn(this.errors.byPath, partialPropString)) return true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to use in and then change errorsByPath to initialize to Object.create(null)?

You are right to consider that edge case but I think solving it in the places where we're using records is better, see #1121

export const appendPropToPathString: AppendPropToPathStringFn = (
path,
prop,
...[opts]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this just be opts without TS complaining? The signature there is really just a TS trick to force opts to be passed in some situations.

Copy link
Contributor Author

@Dimava Dimava Oct 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not without anys
It's possible to make it a function with overloads and loose implementation though

Copy link
Contributor Author

@Dimava Dimava Oct 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I can make it required here, as it's internal anyways

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No that didn't work

@ssalbdivad ssalbdivad merged commit cadbf41 into arktypeio:main Oct 12, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done (merged or closed)
Development

Successfully merging this pull request may close these issues.

2 participants