Skip to content

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

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

juga1980
Copy link

for loops, which fill slices with append, should use capacity for slice(else 0 and reallocations during growing)

@juga1980 juga1980 requested a review from rjl493456442 as a code owner June 24, 2025 15:15
@@ -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))
Copy link
Member

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.

Copy link
Author

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.

@@ -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))
Copy link
Member

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

Copy link
Author

Choose a reason for hiding this comment

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

reverted

@@ -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))
Copy link
Member

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

Copy link
Author

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))
Copy link
Member

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

Copy link
Author

Choose a reason for hiding this comment

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

reverted

@@ -136,11 +136,12 @@ func NewEVMInterpreter(evm *EVM) *EVMInterpreter {
default:
table = &frontierInstructionSet
}
var extraEips []int
extraEips := make([]int, 0, len(evm.Config.ExtraEips))
Copy link
Member

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

Copy link
Author

Choose a reason for hiding this comment

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

reverted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants