-
-
Notifications
You must be signed in to change notification settings - Fork 20.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
[3.x] Add readahead to VariantParser #65079
Conversation
4e461d4
to
72f4b2b
Compare
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.
Looks good to me :) Left a few small nitpicks.
eof = true; | ||
return 0; | ||
} | ||
return get_char(); |
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.
I'm a bit surprised by the recursive call TBH 😛
Could be replaced by the following structure. But it's also fine to keep it the way it is.
if pointer >= filled:
filled = _read_buffer()
if filled == 0:
pointer = 1
eof = true
return 0
pointer = 0
return buffer[pointer++]
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.
Yeah, same result.
One of the reasons I got into the habit of putting the expected result to be the if statement (rather than the else) is that long ago I read the assembly generated tends to favour that branch (much like the unlikely
keyword, before that was available). Whether that is still the case I don't know, have to test in godbolt! 😀
72f4b2b
to
8345413
Compare
Adds a readahead buffer to VariantParser, to prevent large numbers of freads for single bytes, which is inefficient.
8345413
to
29d4d41
Compare
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.
reduz approved the 4.0 PR, so this one should be good too.
Thanks! |
Adds a readahead buffer to VariantParser, to prevent large numbers of freads for single bytes, which is inefficient.
Notes
VariantParser
appears in a lot of places in Godot, and it turns out that it ultimately callsfread
byte by byte (at least on linux), and this can be super slow, even with disk caching.VariantParser
always seems to read in linear order, so isn't subject to some of the pitfalls of readahead (moving the filepointer around etc). This type of access also can be optimized in a way thatfreads
cannot (the file could be changed between each individualfread
, for instance).Measurements
For performance measurements I used a version where the new and old could be
#ifdef
ed between the two, and added a timer around theload_scene()
inEditorNode::open_request()
.