-
Notifications
You must be signed in to change notification settings - Fork 20.9k
add capacity where appends in for can be easily precalculated for less reallocation #32088
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
base: master
Are you sure you want to change the base?
Conversation
core/blockchain.go
Outdated
@@ -2211,7 +2211,7 @@ func (bc *BlockChain) insertSideChain(block *types.Block, it *insertIterator, ma | |||
} | |||
// Import all the pruned blocks to make the state available | |||
var ( | |||
blocks []*types.Block | |||
blocks = make([]*types.Block, 0, len(hashes)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not correct. If the size of blocks
exceed 2k, then the held blocks will be inserted and the slice blocks
will be rotated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted. It focused on the first loop to fit that.
core/rawdb/ancient_utils.go
Outdated
@@ -53,6 +53,7 @@ func (info *freezerInfo) size() common.StorageSize { | |||
|
|||
func inspect(name string, order map[string]freezerTableConfig, reader ethdb.AncientReader) (freezerInfo, error) { | |||
info := freezerInfo{name: name} | |||
info.sizes = make([]tableSize, 0, len(order)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary to pre-allocate, the number of freezer instances is very limited
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted
core/rawdb/ancient_utils.go
Outdated
@@ -78,7 +79,7 @@ func inspect(name string, order map[string]freezerTableConfig, reader ethdb.Anci | |||
|
|||
// inspectFreezers inspects all freezers registered in the system. | |||
func inspectFreezers(db ethdb.Database) ([]freezerInfo, error) { | |||
var infos []freezerInfo | |||
var infos []freezerInfo = make([]freezerInfo, 0, len(freezers)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary to pre-allocate, the number of freezer instances is very limited
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted
core/vm/eips.go
Outdated
@@ -60,7 +60,7 @@ func ValidEip(eipNum int) bool { | |||
return ok | |||
} | |||
func ActivateableEips() []string { | |||
var nums []string | |||
nums := make([]string, 0, len(activators)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary to pre-allocate, the number of EIPs is very limited
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted
core/vm/interpreter.go
Outdated
@@ -136,11 +136,12 @@ func NewEVMInterpreter(evm *EVM) *EVMInterpreter { | |||
default: | |||
table = &frontierInstructionSet | |||
} | |||
var extraEips []int | |||
extraEips := make([]int, 0, len(evm.Config.ExtraEips)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary to pre-allocate, the number of EIPs is very limited
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted
for loops, which fill slices with append, should use capacity for slice(else 0 and reallocations during growing)