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

Improve getBlockByNumber performance with lazy-loaded JSON #266

Merged
merged 4 commits into from
Dec 31, 2024

Conversation

wanliqun
Copy link
Contributor

@wanliqun wanliqun commented Dec 30, 2024

to reduce redundant JSON marshalling and unmarshalling to improve performance


This change is Reviewable

to reduce redundant JSON marshalling and unmarshalling to improve performance
@wanliqun wanliqun requested a review from boqiu December 30, 2024 08:48
@wanliqun wanliqun changed the title Return lazy loaded JSON object for eth_blockNumber Return lazy loaded JSON object for eth_getBlockByNumber Dec 30, 2024
@wanliqun wanliqun changed the title Return lazy loaded JSON object for eth_getBlockByNumber Improve getBlockByNumber performance with lazy-loaded JSON Dec 30, 2024
Copy link
Contributor

@boqiu boqiu left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 3 files at r1, 4 of 4 files at r2, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @wanliqun)


rpc/lazy.go line 8 at r2 (raw file):

)

type lazyDecodedJsonObject[T any] struct {

Better to add necessary comment for performance consideration.


rpc/lazy.go line 9 at r2 (raw file):

type lazyDecodedJsonObject[T any] struct {
	cachedBytes json.RawMessage

Why not use []byte type directly? Because the input parameter type of UnmarshalJSON is []byte.

Copy link
Contributor Author

@wanliqun wanliqun left a comment

Choose a reason for hiding this comment

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

Reviewable status: 3 of 4 files reviewed, 2 unresolved discussions (waiting on @boqiu)


rpc/lazy.go line 8 at r2 (raw file):

Previously, boqiu (Bo QIU) wrote…

Better to add necessary comment for performance consideration.

Done


rpc/lazy.go line 9 at r2 (raw file):

Previously, boqiu (Bo QIU) wrote…

Why not use []byte type directly? Because the input parameter type of UnmarshalJSON is []byte.

I think `json.RawMessage` is okay because it explicitly indicates that the field contains raw JSON data, improving code readability and understanding.

Copy link
Contributor

@boqiu boqiu left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @wanliqun)

@wanliqun wanliqun merged commit d996862 into main Dec 31, 2024
2 checks passed
@wanliqun wanliqun deleted the add-lazy-json-obj branch December 31, 2024 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants