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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions ark/schema/shared/traversal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,11 @@ export class TraversalContext {
pathHasError(path: TraversalPath): boolean {
if (!this.hasError()) return false

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

if (Object.hasOwn(this.errors.byPath, partialPropString)) return true
}
return false
}

get failFast(): boolean {
Expand Down