-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Open
Labels
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Milestone
Description
default := ...
v, ok := m[k]
if !ok {
m[k] = default
v = default
}
// Use v
This is a mapaccess2 followed (conditionally) by a mapassign. The beginning of mapassign is identical to mapaccess2: hashing the key and looking for an existing entry (which won't be found).
In theory, the compiler could detect this pattern and use a special call for the map assignment that avoids the duplicate work (this would effectively be internal/runtime/maps.(*table).uncheckedPutSlot in today's implementation).
Another pattern is iteration plus delete:
for k := range m {
if iDontLikeIt {
delete(m, k)
}
}
It could be optimized in a similar way. This is also maps.DeleteFunc which could be directly specialized more easily than adding new compiler optimizations.
mvdan, mateusz834, thepudds, kscooo, meling and 2 more
Metadata
Metadata
Assignees
Labels
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Type
Projects
Status
Todo