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

preallocated capacity for map's certain usege of memory #29690

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ func decodePrealloc(data string) types.GenesisAlloc {
acc.Nonce = account.Misc.Nonce
acc.Code = account.Misc.Code

acc.Storage = make(map[common.Hash]common.Hash)
acc.Storage = make(map[common.Hash]common.Hash, len(account.Misc.Slots))
for _, slot := range account.Misc.Slots {
acc.Storage[slot.Key] = slot.Val
}
Expand Down
4 changes: 2 additions & 2 deletions node/rpcstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ type virtualHostHandler struct {
}

func newVHostHandler(vhosts []string, next http.Handler) http.Handler {
vhostMap := make(map[string]struct{})
vhostMap := make(map[string]struct{}, len(vhosts))
for _, allowedHost := range vhosts {
vhostMap[strings.ToLower(allowedHost)] = struct{}{}
}
Expand Down Expand Up @@ -636,7 +636,7 @@ func RegisterApis(apis []rpc.API, modules []string, srv *rpc.Server) error {
log.Error("Unavailable modules in HTTP API list", "unavailable", bad, "available", available)
}
// Generate the allow list based on the allowed modules
allowList := make(map[string]bool)
allowList := make(map[string]bool, len(modules))
for _, module := range modules {
allowList[module] = true
}
Expand Down
2 changes: 1 addition & 1 deletion rpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (s *RPCService) Modules() map[string]string {
s.server.services.mu.Lock()
defer s.server.services.mu.Unlock()

modules := make(map[string]string)
modules := make(map[string]string, len(s.server.services.services))
for name := range s.server.services.services {
modules[name] = "1.0"
}
Expand Down
2 changes: 1 addition & 1 deletion triedb/pathdb/nodebuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (b *nodebuffer) commit(nodes map[common.Hash]map[string]*trienode.Node) *no
// The nodes belong to original diff layer are still accessible even
// after merging, thus the ownership of nodes map should still belong
// to original layer and any mutation on it should be prevented.
current = make(map[string]*trienode.Node)
current = make(map[string]*trienode.Node, len(subset))
for path, n := range subset {
current[path] = n
delta += int64(len(n.Blob) + len(path))
Expand Down