Skip to content
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

Merged
merged 28 commits into from
Oct 26, 2023
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
192261b
Problem: parse chain-id from big genesis file could be slow
yihuang Oct 23, 2023
7c59903
Update CHANGELOG.md
yihuang Oct 23, 2023
ee9b00a
fix unit test
yihuang Oct 23, 2023
567ee2d
patch the library to support early abort
yihuang Oct 23, 2023
55be3ec
add benchmarking
yihuang Oct 23, 2023
9c220f5
mention encoding/json/v2
yihuang Oct 23, 2023
c74ba3b
fix error handling
yihuang Oct 23, 2023
7680cdd
fix shadow var
yihuang Oct 23, 2023
1035e32
use simpler solution with different trade off
yihuang Oct 23, 2023
4677221
Merge branch 'main' into parse-chain-id
yihuang Oct 24, 2023
be3a3f7
cleanup
yihuang Oct 24, 2023
7cd0787
skip value more efficiently
yihuang Oct 24, 2023
c84599c
Merge branch 'main' into parse-chain-id
yihuang Oct 24, 2023
df3e2a3
trim space
yihuang Oct 25, 2023
3d7ef1a
trim space
yihuang Oct 25, 2023
b09130e
review suggestions
yihuang Oct 25, 2023
d52f3b6
assert error messages
yihuang Oct 25, 2023
1ad9a8f
Update types/chain_id.go
yihuang Oct 25, 2023
63b604c
use cronos mainnet genesis for benchmark
yihuang Oct 25, 2023
a4cc48a
fix conflicts
yihuang Oct 25, 2023
7a58af1
Merge branch 'main' into parse-chain-id
yihuang Oct 25, 2023
5147d1c
fix cyclic import
yihuang Oct 25, 2023
5d99b23
Merge branch 'main' into parse-chain-id
yihuang Oct 25, 2023
ba767d9
fix lint
yihuang Oct 25, 2023
2d3ba07
move directory
yihuang Oct 26, 2023
310b580
Merge branch 'main' into parse-chain-id
yihuang Oct 26, 2023
5145bac
Update x/genutil/types/chain_id.go
yihuang Oct 26, 2023
1bb078f
Merge branch 'main' into parse-chain-id
julienrbrt Oct 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
mention encoding/json/v2
  • Loading branch information
yihuang committed Oct 23, 2023
commit 9c220f59d7d5e648163d8dce0e34442572c747d4
2 changes: 2 additions & 0 deletions types/chain_id.go
Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
"errors"
"io"

"github.com/bcicen/jstream"

Check failure on line 7 in types/chain_id.go

View workflow job for this annotation

GitHub Actions / dependency-review

missing go.sum entry for module providing package github.com/bcicen/jstream (imported by github.com/cosmos/cosmos-sdk/types); to add:

Check failure on line 7 in types/chain_id.go

View workflow job for this annotation

GitHub Actions / dependency-review

missing go.sum entry for module providing package github.com/bcicen/jstream (imported by github.com/cosmos/cosmos-sdk/types); to add:

Check failure on line 7 in types/chain_id.go

View workflow job for this annotation

GitHub Actions / dependency-review

missing go.sum entry for module providing package github.com/bcicen/jstream (imported by github.com/cosmos/cosmos-sdk/types); to add:

Check failure on line 7 in types/chain_id.go

View workflow job for this annotation

GitHub Actions / dependency-review

missing go.sum entry for module providing package github.com/bcicen/jstream (imported by github.com/cosmos/cosmos-sdk/types); to add:

Check failure on line 7 in types/chain_id.go

View workflow job for this annotation

GitHub Actions / dependency-review

missing go.sum entry for module providing package github.com/bcicen/jstream (imported by github.com/cosmos/cosmos-sdk/types); to add:

Check failure on line 7 in types/chain_id.go

View workflow job for this annotation

GitHub Actions / dependency-review

missing go.sum entry for module providing package github.com/bcicen/jstream (imported by github.com/cosmos/cosmos-sdk/types); to add:

Check failure on line 7 in types/chain_id.go

View workflow job for this annotation

GitHub Actions / dependency-review

missing go.sum entry for module providing package github.com/bcicen/jstream (imported by github.com/cosmos/cosmos-sdk/types); to add:

Check failure on line 7 in types/chain_id.go

View workflow job for this annotation

GitHub Actions / dependency-review

missing go.sum entry for module providing package github.com/bcicen/jstream (imported by github.com/cosmos/cosmos-sdk/types); to add:

Check failure on line 7 in types/chain_id.go

View workflow job for this annotation

GitHub Actions / dependency-review

missing go.sum entry for module providing package github.com/bcicen/jstream (imported by github.com/cosmos/cosmos-sdk/types); to add:
yihuang marked this conversation as resolved.
Show resolved Hide resolved
)

const ChainIDFieldName = "chain_id"

// ParseChainIDFromGenesis parses the chain-id from the genesis file using constant memory.
//
// TODO consider [encoding/json/v2](https://github.com/golang/go/discussions/63397) when it's ready.
func ParseChainIDFromGenesis(reader io.Reader) (string, error) {
decoder := jstream.NewDecoder(reader, 1).EmitKV()
var chain_id string
Expand Down
Loading