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

Compilation: read entire source into a buffer before processing it #520

Merged
merged 3 commits into from
Oct 10, 2023

Conversation

ehaas
Copy link
Collaborator

@ehaas ehaas commented Oct 9, 2023

Instead of reading one byte at a time via a reader, just read the whole thing into a []u8 and operate on it from there.

Not sure why I did it one byte at a time via a reader originally but this way is faster:

parsing sqlite3.c, master branch

real	0m0.358s
user	0m0.342s

parsing sqlite3.c, this branch,

real	0m0.333s
user	0m0.304s

Tests in ReleaseFast, master branch

real	0m3.036s
user	0m23.240s

Tests in ReleaseFast, this branch:

real	0m2.733s
user	0m20.778s

Instead of reading one byte at a time via a reader, just read the
whole thing into a []u8 and operate on it from there.
Comment on lines 1087 to 1089
// Important: do not perform any possibly-failing operations in this function after this realloc.
// Otherwise errdefers in callers will possibly free the realloced slice using the original len
// instead of the new
Copy link
Contributor

Choose a reason for hiding this comment

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

Check this out, you can put this on the next line:

errdefer @compileError("errdefers in callers would possibly free the realloced slice using the original len");

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh wow, that's awesome!

ehaas added 2 commits October 9, 2023 16:35
Trick the compiler into thinking error.StreamTooLong can be returned
from addSourceFromBuffer in 32-bit builds
@Vexu Vexu merged commit f9cfff0 into Vexu:master Oct 10, 2023
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.

3 participants