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

Specialize parsing of blocks of the same elements #24

Merged
merged 1 commit into from
Mar 30, 2024
Merged

Conversation

w0rm
Copy link
Owner

@w0rm w0rm commented Mar 30, 2024

Having read the "Use specialization" section of https://romgrk.com/posts/optimizing-javascript#9-use-specialization I got another idea for performance optimization.

Oftentimes, the lines that define vertices, normals, uvs and faces are grouped. This means that if the parser encounters a line that defines a vertex (starting with v), it could switch into the mode of parsing only vertices until it sees something else. In this mode, each next line only needs to be checked if it starts with v, instead of being considered for any other possibility.

This made the parser 24% faster in Safari

safari

And 6% faster in Chrome

chrome

@w0rm w0rm merged commit 9d08b74 into main Mar 30, 2024
1 check passed
@w0rm w0rm deleted the perf-improvement branch March 30, 2024 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant