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.
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
perf: parse chain-id from big genesis file could be slow #18204
perf: parse chain-id from big genesis file could be slow #18204
Changes from 5 commits
192261b
7c59903
ee9b00a
567ee2d
55be3ec
9c220f5
c74ba3b
7680cdd
1035e32
4677221
be3a3f7
7cd0787
c84599c
df3e2a3
3d7ef1a
b09130e
d52f3b6
1ad9a8f
63b604c
a4cc48a
7a58af1
5147d1c
5d99b23
ba767d9
2d3ba07
310b580
5145bac
1bb078f
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 we maybe move this to genutil? Imho this makes more sense to have it there as its genesis related than in 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.
done
Check failure on line 7 in types/chain_id.go
GitHub Actions / dependency-review
Check failure on line 7 in types/chain_id.go
GitHub Actions / dependency-review
Check failure on line 7 in types/chain_id.go
GitHub Actions / dependency-review
Check failure on line 7 in types/chain_id.go
GitHub Actions / dependency-review
Check failure on line 7 in types/chain_id.go
GitHub Actions / dependency-review
Check failure on line 7 in types/chain_id.go
GitHub Actions / dependency-review
Check failure on line 7 in types/chain_id.go
GitHub Actions / dependency-review
Check failure on line 7 in types/chain_id.go
GitHub Actions / dependency-review
Check failure on line 7 in types/chain_id.go
GitHub Actions / dependency-review
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 function
ParseChainIDFromGenesis
uses thejstream
library to parse the JSON genesis file. It's a good approach to use a streaming JSON parser for large files as it uses constant memory. However, there's a potential issue with error handling. In line 19, the error from the type assertionkv.Value.(string)
is ignored. Ifkv.Value
is not a string, this will not cause a panic due to the use of the "comma ok" idiom, butchain_id
will be an empty string and no error will be reported at this stage. This could lead to misleading errors, as the function will later return an error stating that the "chain-id was not found in the genesis file", even though it was found but was not a string. Consider handling this error to provide more accurate feedback.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 error handling here could be improved for clarity. If
chain_id
is empty anderr
is notnil
, the function will return an error stating that the "chain-id was not found in the genesis file", even though the error might be unrelated to the presence of the chain-id. Consider checkingerr
first and returning it if it's notnil
, before checking ifchain_id
is empty.