-
Notifications
You must be signed in to change notification settings - Fork 36
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
msgpack: optimize #95
Draft
zchee
wants to merge
6
commits into
main
Choose a base branch
from
msgpack/optimize
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1a5bcd6
msgpack: sort formats struct to msgpack code order
zchee 270e5a4
msgpack: rename formats n field to fn
zchee 08cb85b
msgpack: remove unused format arg name
zchee c229f6c
msgpack: sort type and function
zchee 7e7bcb6
msgpack: split type switch case to reflect.Int specific case
zchee 2732b5d
msgpack: add bounds check hint to compiler to fields
zchee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you elaborate on that? I've seen bounds checks (namely the std lib) to guard a specific length of a slice, but not ever like this
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.
This commit is very old so I don't remember that, but IIRC scope is
for i := 0; i < len(fields); i++
.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, but when do you expect
len(fields)
to go out of bounds? Usually I've seen bound checks like these guard a slice of unknown length when we're explicitly accessing certain indexes like this:While what you've done here is you're not guarding an explicit length like:
_ = fields[3]
but guarding the size which is restricted by the language itself, that is: the last index has to belen(slice)-1
, there's no other way. It seems completely redundant to me and confusing.Am I missing something? :)
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'll re-detect where is BCE optimized using
-gcflags='-d=ssa/check_bce/debug=3'
.But in context of language specifications, the
fields
value is not array, actual type is slice. It means, the gc compiler (still can't optimization? I don't know) might be imagine will growing slice. And actually we also can growfields
slice after the BCE'ed place.e.g.,
encoding/binary
package isreturn
byte slice immediately after the BCE place, but this msgpack packages logic is usedfor
loop (and etc) after the BCE place, therefore works BCE optimization. (above is my current imagine. I'll verify again that the BCE is working properly when I have time anyway.)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.
interesting!
Still,
fields
is not local to thecollect
function and might be manipulated after you do the bounds check so you won't really eliminate the BCE done onfields[j] = fields[i]
, I've verified that with this whole file:You can see you've just introduced an extra check there and haven't got rid of the ones performed in the loop.
Correct me If I'm wrong and thanks a lot for answering, this is quiet interesting! :)