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

fix: call initContract only when initializing consensus and Authorize #243

Merged
merged 1 commit into from
Mar 17, 2023

Conversation

minh-bq
Copy link
Contributor

@minh-bq minh-bq commented Mar 16, 2023

When profiling node sync with low number of transactions in block, we realize that initContract which unmarshalls JSON innerly consumes around 45% CPU. It is because we call initContract every time we want to call to contract which is redundant and this wastes a lot of CPU. We only need to call initContract when intializing the consensus engine and in Authorize function.

Before this commit:

  • 44.92% 0.00% ronin ronin [.] github.com/ethereum/go-ethereum/consensus/consortium/v2.(*Consortium).initContract
  • 44.91% 0.00% ronin ronin [.] github.com/ethereum/go-ethereum/consensus/consortium/common.NewContractIntegrator
  • 44.79% 0.00% ronin ronin [.] github.com/ethereum/go-ethereum/accounts/abi.JSON

After this commit:

  • 43.30% 0.00% ronin ronin [.] github.com/ethereum/go-ethereum/eth/downloader.(*Downloader).spawnSync.func1
  • 42.98% 0.00% ronin ronin [.] github.com/ethereum/go-ethereum/eth/downloader.(*Downloader).importBlockResults
  • 42.98% 0.00% ronin ronin [.] github.com/ethereum/go-ethereum/eth/downloader.(*Downloader).processFullSyncContent

When profiling node sync with low number of transactions in block, we realize
that initContract which unmarshalls JSON innerly consumes around 45% CPU. It is
because we call initContract every time we want to call to contract which is
redundant and this wastes a lot of CPU. We only need to call initContract when
intializing the consensus engine and in Authorize function.

Before this commit:

+   44.92%     0.00%  ronin    ronin                [.] github.com/ethereum/go-ethereum/consensus/consortium/v2.(*Consortium).initContract
+   44.91%     0.00%  ronin    ronin                [.] github.com/ethereum/go-ethereum/consensus/consortium/common.NewContractIntegrator
+   44.79%     0.00%  ronin    ronin                [.] github.com/ethereum/go-ethereum/accounts/abi.JSON

After this commit:

+   43.30%     0.00%  ronin    ronin                [.] github.com/ethereum/go-ethereum/eth/downloader.(*Downloader).spawnSync.func1
+   42.98%     0.00%  ronin    ronin                [.] github.com/ethereum/go-ethereum/eth/downloader.(*Downloader).importBlockResults
+   42.98%     0.00%  ronin    ronin                [.] github.com/ethereum/go-ethereum/eth/downloader.(*Downloader).processFullSyncContent
@minh-bq minh-bq requested review from DNK90 and linh-1 March 16, 2023 06:42
@minh-bq minh-bq merged commit e76aa38 into axieinfinity:master Mar 17, 2023
@minh-bq minh-bq deleted the fix/init-contract branch March 17, 2023 03:32
andicrypt pushed a commit to andicrypt/ronin that referenced this pull request Nov 1, 2023
…axieinfinity#243)

When profiling node sync with low number of transactions in block, we realize
that initContract which unmarshalls JSON innerly consumes around 45% CPU. It is
because we call initContract every time we want to call to contract which is
redundant and this wastes a lot of CPU. We only need to call initContract when
intializing the consensus engine and in Authorize function.

Before this commit:

+   44.92%     0.00%  ronin    ronin                [.] github.com/ethereum/go-ethereum/consensus/consortium/v2.(*Consortium).initContract
+   44.91%     0.00%  ronin    ronin                [.] github.com/ethereum/go-ethereum/consensus/consortium/common.NewContractIntegrator
+   44.79%     0.00%  ronin    ronin                [.] github.com/ethereum/go-ethereum/accounts/abi.JSON

After this commit:

+   43.30%     0.00%  ronin    ronin                [.] github.com/ethereum/go-ethereum/eth/downloader.(*Downloader).spawnSync.func1
+   42.98%     0.00%  ronin    ronin                [.] github.com/ethereum/go-ethereum/eth/downloader.(*Downloader).importBlockResults
+   42.98%     0.00%  ronin    ronin                [.] github.com/ethereum/go-ethereum/eth/downloader.(*Downloader).processFullSyncContent
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