Repository navigation
perf: reduce heap allocations #38
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Binaries for programs and plugins | ||
| *.exe | ||
| *.exe~ | ||
| *.dll | ||
| *.so | ||
| *.dylib | ||
|
|
||
| # Test binary, built with `go test -c` | ||
| *.test | ||
|
|
||
| # Output of the go coverage tool, specifically when used with LiteIDE | ||
| *.out | ||
|
|
||
| # Dependency directories (remove the comment below to include it) | ||
| # vendor/ | ||
|
|
||
| # Go workspace file | ||
| go.work | ||
| go.work.sum | ||
| .idea | ||
|
|
||
| # env file | ||
| .env | ||
|
|
||
| .DS_Store | ||
| nylon | ||
|
|
||
| central.key | ||
| central.yaml | ||
| node.yaml | ||
| central.nybundle | ||
|
|
||
| distribute.sh | ||
| distribute-conf.sh | ||
| log | ||
|
|
||
| log.csv | ||
|
|
||
| vendor | ||
|
|
||
| workdir | ||
| Dockerfile |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,4 +36,6 @@ log | |
|
|
||
| log.csv | ||
|
|
||
| vendor | ||
| vendor | ||
|
|
||
| workdir | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -438,6 +438,54 @@ func (device *Device) RoutineEncryption(id int) { | |||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /* | ||||||||||
| This function arranges buffers and endpoints by endpoint, into contiguous | ||||||||||
| segments of endpoints. It ensures that packets within the same endpoint group | ||||||||||
| are stable-ordered. | ||||||||||
| */ | ||||||||||
| func partitionBuffersByEndpoint(bufs [][]byte, eps []conn.Endpoint, outBufs *[][]byte, outEps *[]conn.Endpoint, peer *Peer) error { | ||||||||||
| // use a naive O(n^2) algorithm since n is expected to be small | ||||||||||
|
|
||||||||||
| // replace nil endpoints with the first known endpoint | ||||||||||
| peer.endpoints.Lock() | ||||||||||
| for i := 0; i < len(eps); i++ { | ||||||||||
| if eps[i] == nil { | ||||||||||
| if len(peer.endpoints.val) == 0 { | ||||||||||
| peer.endpoints.Unlock() | ||||||||||
| return errors.New("no known endpoints for peer") | ||||||||||
| } | ||||||||||
| eps[i] = peer.endpoints.val[0] | ||||||||||
| } | ||||||||||
| } | ||||||||||
| peer.endpoints.Unlock() | ||||||||||
|
|
||||||||||
| for i := 0; i < len(bufs); i++ { | ||||||||||
| // If endpoint is nil, it has already been processed | ||||||||||
| // as part of an earlier group. | ||||||||||
|
Comment on lines
+463
to
+464
|
||||||||||
| // If endpoint is nil, it has already been processed | |
| // as part of an earlier group. | |
| // If endpoint is nil, it was marked as visited during this loop | |
| // and has already been processed as part of an earlier group. |
Copilot
AI
Nov 9, 2025
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.
The lock acquired at line 526 via elemsContainer.Lock() is not released before the continue statement when partitionBuffersByEndpoint returns an error. This will cause a deadlock. The unlock should happen before continuing, or the cleanup code (lines 547-551) should be executed even on error.
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.
Potential panic if
epsslice is empty. Line 149 accesseseps[0]without checking if the slice has any elements. While the current code flow may prevent empty slices from reaching this function, defensive programming would suggest adding a length check or early return for empty inputs.