Skip to content

Commit

Permalink
Merge pull request ethereum#472 from binance-chain/bitmap_cache_metrics
Browse files Browse the repository at this point in the history
[R4R]add metrics for contract code bitmap cache
  • Loading branch information
unclezoro authored Oct 21, 2021
2 parents 7ba77c5 + a04ee70 commit 60e92c1
Showing 1 changed file with 9 additions and 1 deletion.
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

0 comments on commit 60e92c1

Please sign in to comment.