-
Notifications
You must be signed in to change notification settings - Fork 261
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
SSZ cleanup #1073
SSZ cleanup #1073
Conversation
arnetheduck
commented
May 27, 2020
- be stricter about SSZ length prefix
- compute zeroHash list at compile time
- remove SSZ schema stuff
- move SSZ navigation to ncli
- cleanup a few leftover openArray uses
* be stricter about SSZ length prefix * compute zeroHash list at compile time * remove SSZ schema stuff * move SSZ navigation to ncli * cleanup a few leftover openArray uses
What is the compilation time increase stemming from this? Not slowing down compilation was the primary motivation for me for not doing it this way. |
@@ -961,25 +961,3 @@ programMain: | |||
config.depositContractAddress, | |||
config.depositPrivateKey, | |||
delayGenerator) | |||
|
|||
of query: |
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.
The query commands are currently used in the multinet repo to extract the genesis time (we used to rely on JSON in the past).
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 they be updated to use ncli
? the navigation brings in a bunch of memrange code that I'd rather avoid in the beacon_node
proper
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.
Sure, what I meant is that it would be nice to do a PR there as well that will land together with this one.
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.
@onqtam can you help with this? you've been looking at the multinet scrips recently - it would involve building ncli_query.
generally I feel the feature would be better off if it supported something like graphql as query language
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.
@arnetheduck actually 1+ month ago zahary told me that I could modernize the multinet scripts from parsing the json file to using this query subcommand but I never did it since what we had was already working (in terms of extracting the genesis time at least - my bad), so it should be fine to remove this. I could still migrate the scripts there to use ncli
, but that would be unrelated to this PR - this change should be good to go.
beacon_chain/ssz.nim
Outdated
@@ -63,6 +66,18 @@ serializationFormat SSZ, | |||
Writer = SszWriter, | |||
PreferedOutput = seq[byte] | |||
|
|||
template decode*(Format: type SSZ, |
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.
Why do you need these?
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.
to pass the more conservative maxObjectSize
without having to change all call sites
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.
ie the branch removes the arbitrary default - I haven't looked at it in detail, but the SSZ library should always know and use the length of the given buffer to constrain the instances it creates - this is a security feature to fail fast on any overlong length
fields that would otherwise try to cause the library to allocate a large seq of stuff without backing it up with actual contents
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 think maxObjectSize
should be removed altogether. It was a temporary way of doing things that is no longer necessary with some improvements in the FastStreams API such as withReadableRange
.
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.
ok - that's beyond my familiarity with the serialization stuff, sounds like something for a separate PR at which point removing these two overloads is trivial
beacon_chain/ssz/bytes_reader.nim
Outdated
result = T readSszValue(input, List[byte, maxExpectedSize]) | ||
const maxExpectedSize = (val.maxLen div 8) + 1 | ||
# TODO can't cast here.. | ||
var v: List[byte, maxExpectedSize] |
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.
Why is the unnecessary copy produced here?
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.
because there was a weird compiler error I was unable to fix in reasonable time, when trying to pass (List[byte,..)(val)
, complaining that it's not a var
any more
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.
Well, let's not introduce performance regressions in cleanup PRs. After all, this is a list, one of the largest structures that appear in the consensus data types.
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.
the alternative is a stack overflow because of the bug with arrays and RVO - I don't understand the compiler error tbh, maybe you have any good ideas? all that should be needed here is a cast
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.
also, it's a bitlist
- ie typically a very small - we have no idea about the performance impact of all these bugs, but generally, this branch does not noticeably slow anything down (on the contrary, I would suspect it speeds things up because of the bugs it works around) - but all these things are idle speculation since we don't benchmark things, which would be the way to actually tell - like we've seen in the past, since 20 copies on the way from the network to ssz decode don't matter, neither will this seq copy - focus on the right things before bringing up performance
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 hadn't noticed that this is the BitList
branch indeed. It's less of a concern then, but I'll take a look at the compilation error.
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.
you can cast[var List[byte,...]](val.addr)
as a workaround. Known issue with distinct types or pointer(...)
conversion
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.
Yes, I've reached the same conclusion here:
239224d
Found a Nim bug along the way :)
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 glad we're keeping the nim-bugs-per-PR ratio stable
pre:
post:
|
I've made some local tests by increasing the size of the You can improve this further by computing the precise number of |
I put the limit at 64 which allows lists up to given the overall compile time goes down with this branch, I'm pretty happy - full picture > OCD |
Rebased here: |