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

[R4R]add metrics for contract code bitmap cache #472

Merged
merged 1 commit into from
Oct 21, 2021
Merged
Changes from all commits
Commits
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
10 changes: 9 additions & 1 deletion core/vm/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@ import (
lru "github.com/hashicorp/golang-lru"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/metrics"
"github.com/holiman/uint256"
)

const codeBitmapCacheSize = 2000

var codeBitmapCache, _ = lru.New(codeBitmapCacheSize)
var (
codeBitmapCache, _ = lru.New(codeBitmapCacheSize)

contractCodeBitmapHitMeter = metrics.NewRegisteredMeter("vm/contract/code/bitmap/hit", nil)
contractCodeBitmapMissMeter = metrics.NewRegisteredMeter("vm/contract/code/bitmap/miss", nil)
)

// ContractRef is a reference to the contract's backing object
type ContractRef interface {
Expand Down Expand Up @@ -117,12 +123,14 @@ func (c *Contract) isCode(udest uint64) bool {
analysis, exist := c.jumpdests[c.CodeHash]
if !exist {
if cached, ok := codeBitmapCache.Get(c.CodeHash); ok {
contractCodeBitmapHitMeter.Mark(1)
analysis = cached.(bitvec)
} else {
// Do the analysis and save in parent context
// We do not need to store it in c.analysis
analysis = codeBitmap(c.Code)
c.jumpdests[c.CodeHash] = analysis
contractCodeBitmapMissMeter.Mark(1)
codeBitmapCache.Add(c.CodeHash, analysis)
}
}
Expand Down