-
Notifications
You must be signed in to change notification settings - Fork 712
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
Parsing optimisations #2937
Parsing optimisations #2937
Conversation
render/id.go
Outdated
@@ -66,7 +65,8 @@ func externalNodeID(n report.Node, addr string, local report.Networks) (string, | |||
|
|||
// If the dstNodeAddr is not in a network local to this report, we emit an | |||
// internet pseudoNode | |||
if ip := net.ParseIP(addr); ip != nil && !local.Contains(ip) { | |||
var into [5]byte // one extra byte to save a memory allocation in critbitgo | |||
if ip := report.ParseIPb([]byte(addr), into[:4]); ip != nil && !local.Contains(ip) { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
report/networks.go
Outdated
|
||
// ParseIP parses s as an IP address into a byte slice if supplied, returning the result. | ||
// (mostly copied from net.ParseIP, modified to save memory allocations) | ||
func ParseIPb(s []byte, into []byte) net.IP { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
if second == -1 { | ||
return "", "", "", false | ||
} | ||
return endpointNodeID[:first], endpointNodeID[first+1 : first+1+second], endpointNodeID[first+1+second+1:], true |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
These routines are called a lot, so this change reduces garbage collection
Pass in a slice on the stack instead of allocating one on the heap: reduces garbage, hence makes the program run faster Also apply knowledge that critbitgo will do an append() with one extra byte, so we do that allocation up-front too. This is innocuous should we stop using critbitgo or should its internals change.
41e33ed
to
b989006
Compare
Make low-level parsing more closely aligned to what we need, to save memory allocations.
See individual commit messages for more details.
These routines are called a lot, so this change reduces garbage collection
Benchmarks before (c5bdebd):
after this PR: