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
sstable: generate streamlined blockIter code #3373
base: master
Are you sure you want to change the base?
Conversation
fdf1c5e
to
9ee5a1f
Compare
Comments directly inside the method are missing. I couldn't quite figure out how to fix that, but it doesn't really matter (everyone should always work with the original code). |
126e941
to
53a81d3
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 straightforward and understandable. Other storage folks should definitely give this a review, but I'm thumbs-up on an approach like this.
Reviewable status: 0 of 7 files reviewed, 4 unresolved discussions (waiting on @RaduBerinde)
sstable/block-iter-codegen/main.go
line 5 at r4 (raw file):
// the LICENSE file. package main
It's worthwhile to add a comment explaining what this code is doing. It is relatively straightforward, but I still suspect our future selves will thank us. Especially if this code grows more complex over time.
sstable/block-iter-codegen/main.go
line 18 at r4 (raw file):
) var methods = map[string]struct{}{
Rather than maintaining a list of methods like this, could you automatically deduce the methods by walking over the function declarations and marking any method which references the streamlinedBlockIter
constant and any method which transitively calls such a method as needing a rewrite? I'm hoping you'll get the same list (though you might want to exclude init
), but then we don't have the possibility of introducing another streamlinedBlockIter
path and forget to update this list.
sstable/block-iter-codegen/main.go
line 46 at r4 (raw file):
} // Rename streamlinedBlockIter ot streamlinedBlockIterTrue.
Is this comment still valid? Seems like you're doing more than what the comment states.
Nit: s/ot/to/g
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.
Reviewable status: 0 of 7 files reviewed, 4 unresolved discussions (waiting on @petermattis)
sstable/block-iter-codegen/main.go
line 5 at r4 (raw file):
Previously, petermattis (Peter Mattis) wrote…
It's worthwhile to add a comment explaining what this code is doing. It is relatively straightforward, but I still suspect our future selves will thank us. Especially if this code grows more complex over time.
Agreed, it's just an initial draft
sstable/block-iter-codegen/main.go
line 18 at r4 (raw file):
Previously, petermattis (Peter Mattis) wrote…
Rather than maintaining a list of methods like this, could you automatically deduce the methods by walking over the function declarations and marking any method which references the
streamlinedBlockIter
constant and any method which transitively calls such a method as needing a rewrite? I'm hoping you'll get the same list (though you might want to excludeinit
), but then we don't have the possibility of introducing anotherstreamlinedBlockIter
path and forget to update this list.
Interesting. I think I'd need some more advanced walking infrastructure than Inspect. Might not be worth the trouble, but I'll give it a shot
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.
Reviewable status: 0 of 7 files reviewed, 4 unresolved discussions (waiting on @RaduBerinde)
sstable/block-iter-codegen/main.go
line 18 at r4 (raw file):
Previously, RaduBerinde wrote…
Interesting. I think I'd need some more advanced walking infrastructure than Inspect. Might not be worth the trouble, but I'll give it a shot
Yeah, my suggestion may not be worth the effort. Perhaps just leave a TODO comment in case this becomes some sort of headache in the future.
Previously, petermattis (Peter Mattis) wrote…
I looked at it briefly and I think it's not bad at all, when I get it working I'll update and we can decide then. |
6275b88
to
2901c89
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.
Reviewable status: 0 of 7 files reviewed, 4 unresolved discussions (waiting on @petermattis)
sstable/block-iter-codegen/main.go
line 5 at r4 (raw file):
Previously, RaduBerinde wrote…
Agreed, it's just an initial draft
Done.
sstable/block-iter-codegen/main.go
line 18 at r4 (raw file):
Previously, RaduBerinde wrote…
I looked at it briefly and I think it's not bad at all, when I get it working I'll update and we can decide then.
Done.
2901c89
to
ee9934e
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.
This all looks good to me, but let's get some other Storage 👀 on this PR.
Reviewable status: 0 of 7 files reviewed, 4 unresolved discussions (waiting on @RaduBerinde)
sstable/block_iter_streamlined.gen.go
line 19 at r2 (raw file):
Previously, RaduBerinde wrote…
Comments directly inside the method are missing. I couldn't quite figure out how to fix that, but it doesn't really matter (everyone should always work with the original code).
Hmm, I thought that parser.ParseComments
flag would have handled keeping the comments around. Perhaps there is a similar flag that needs to be specified when outputting the AST. I see there is a printer.CommentedNode
type. I agree that this isn't worth worrying about.
sstable/block-iter-codegen/main.go
line 18 at r4 (raw file):
Previously, RaduBerinde wrote…
Done.
Nice!
sstable/block-iter-codegen/main.go
line 10 at r5 (raw file):
// // The block_iter.go code uses a special constant streamlinedBlockIter which is // always false in th code. This program generates streamlined versions of the
Nit: s/th/the/g
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.
TFTR! I will rope in some more reviewers once I wire it up and maybe demonstrate some gains by inlining the crdb comparer.
Reviewable status: 0 of 7 files reviewed, 3 unresolved discussions (waiting on @petermattis)
sstable/block_iter_streamlined.gen.go
line 19 at r2 (raw file):
Previously, petermattis (Peter Mattis) wrote…
Hmm, I thought that
parser.ParseComments
flag would have handled keeping the comments around. Perhaps there is a similar flag that needs to be specified when outputting the AST. I see there is aprinter.CommentedNode
type. I agree that this isn't worth worrying about.
Yeah, me too. It does keep most comments, just not the ones that are at the top level inside the body. Apparently they are in separate nodes or something like that.
Previously, RaduBerinde wrote…
Yeah, the missing ones all show up under |
We automatically generate a "streamlined" version of the blockIter code (in `block_iter_streamlined.gen.go`). The streamlined code can be used in the common case and does not support all features. This improves performance by reducing the conditionals in the hot path. The streamlinedBlockIter constant can be used in if statements; in the streamlined version, it gets replaced by "true" (allowing the compiler to omit blocks of code from the streamlined version).
ee9934e
to
7bf6533
Compare
sstable: separate blockIter code
sstable: generate streamlined blockIter code
We automatically generate a "streamlined" version of the blockIter code (in
block_iter_streamlined.gen.go). The streamlined code can be used in the
common case and does not support all features. This improves performance by
reducing the conditionals in the hot path.
The streamlinedBlockIter constant can be used in if statements; in the
streamlined version, it gets replaced by "true" (allowing the compiler to
omit blocks of code from the streamlined version).