Repository navigation
perf: stop pinning a first commit's item buffer, and one style per node - #7
Merged
Merged
Conversation
Each node held a Style (976 B) for its StyleFunc result even when it had none, and the render effect allocated a fresh one on every call. Keep a pointer, allocate it once, and update it in place: node drops 5696 -> 4728 bytes, and a table of 200 rows saves ~5 MB.
The first commit sends every view, so its scratch slice grew to the whole tree's worth of items (38k x 368 B for a 200-row table) and stayed the tree's capacity for good, while a steady commit sends tens. Release it once the queue is small again, keeping a floor so it does not thrash.
Both are memory regressions that no assertion of the rendered output would catch: - a first commit's peak stays the tree's item capacity (cap 14892 here), - a StyleFunc allocates a 976 B Style per render effect when the node could keep one. Verified as failing before the fixes: the buffer test reports cap 14892 -> 14892, the style test does not compile against the old value field.
oneo-me
force-pushed
the
perf/node-alloc
branch
from
October 26, 2026 13:00
9c2495b to
d3afad0
Compare
Collaborator
|
Thanks! Both fixes hold up, so I'm merging this.
|
togotop
pushed a commit
to togotop/nsgo
that referenced
this pull request
Nov 16, 2026
A Windows download that carries no signature, or one from a certificate SmartScreen does not know, warns the user before it opens. MyGo signs Windows packages; NSGo wrote them unsigned, and Windows code signing was a roadmap gap. Add it here without the Windows SDK, so a Mac signs what it builds: - internal package cmd/nsgo/authenticode signs a PE image: it parses the headers, computes the Authenticode digest (headers without the checksum and certificate table entry, every section in file order, the bytes between and after them, a short last block padded to 8 bytes), writes a WIN_CERTIFICATE holding a PKCS nsgo-dev#7 SignedData over SpcIndirectDataContent and recomputes the PE checksum. A re-signed image replaces the old signature rather than appending a second. The digest covers SpcIndirectDataContent's value, not its SEQUENCE header, as Authenticode readers check it. - sign.certificate (a .pfx, NSGO_CERTIFICATE_PASSWORD) signs the executable, the command companion, the resources' PE images that carry no signature, and the installer. sign.sign_command signs them with a tool of its own, %1 standing for the path, for a hardware token or a cloud service. sign.timestamp_url, DigiCert's unless "none", asks an RFC 3161 server for a token, which the signer carries as its unsigned attribute so the signature outlives the certificate. - The installer's uninstaller comes from makensis, so it signs through NSIS's !uninstfinalize running `nsgo sign-uninstaller` with the certificate in the environment; that needs NSIS 3.08, and without it the uninstaller stays unsigned. - -certificate, -sign-command and -timestamp-url replace the three from the command line. build refuses two ways of signing at once, a certificate on a build that names no Windows target, and it refuses a certificate outside a release build. Verified: the package's tests, including osslsigncode's verification of an image signed here, and a real build of examples/hello whose exe, setup and uninstaller each verify with osslsigncode. The MSIX stays unsigned: AppxSignature.p7x is a package signature of its own, recorded in the roadmap.
togotop
pushed a commit
to togotop/nsgo
that referenced
this pull request
Nov 16, 2026
A Windows download that carries no signature, or one from a certificate SmartScreen does not know, warns the user before it opens. MyGo signs Windows packages; NSGo wrote them unsigned, and Windows code signing was a roadmap gap. Add it here without the Windows SDK, so a Mac signs what it builds: - internal package cmd/nsgo/authenticode signs a PE image: it parses the headers, computes the Authenticode digest (headers without the checksum and certificate table entry, every section in file order, the bytes between and after them, a short last block padded to 8 bytes), writes a WIN_CERTIFICATE holding a PKCS nsgo-dev#7 SignedData over SpcIndirectDataContent and recomputes the PE checksum. A re-signed image replaces the old signature rather than appending a second. The digest covers SpcIndirectDataContent's value, not its SEQUENCE header, as Authenticode readers check it. - sign.certificate (a .pfx, NSGO_CERTIFICATE_PASSWORD) signs the executable, the command companion, the resources' PE images that carry no signature, and the installer. sign.sign_command signs them with a tool of its own, %1 standing for the path, for a hardware token or a cloud service. sign.timestamp_url, DigiCert's unless "none", asks an RFC 3161 server for a token, which the signer carries as its unsigned attribute so the signature outlives the certificate. - The installer's uninstaller comes from makensis, so it signs through NSIS's !uninstfinalize running `nsgo sign-uninstaller` with the certificate in the environment; that needs NSIS 3.08, and without it the uninstaller stays unsigned. - -certificate, -sign-command and -timestamp-url replace the three from the command line. build refuses two ways of signing at once, a certificate on a build that names no Windows target, and it refuses a certificate outside a release build. Verified: the package's tests, including osslsigncode's verification of an image signed here, and a real build of examples/hello whose exe, setup and uninstaller each verify with osslsigncode. The MSIX stays unsigned: AppxSignature.p7x is a package signature of its own, recorded in the roadmap.
houko
pushed a commit
to togotop/nsgo
that referenced
this pull request
Nov 16, 2026
A Windows download that carries no signature, or one from a certificate SmartScreen does not know, warns the user before it opens. MyGo signs Windows packages; NSGo wrote them unsigned, and Windows code signing was a roadmap gap. Add it here without the Windows SDK, so a Mac signs what it builds: - internal package cmd/nsgo/authenticode signs a PE image: it parses the headers, computes the Authenticode digest (headers without the checksum and certificate table entry, every section in file order, the bytes between and after them, a short last block padded to 8 bytes), writes a WIN_CERTIFICATE holding a PKCS nsgo-dev#7 SignedData over SpcIndirectDataContent and recomputes the PE checksum. A re-signed image replaces the old signature rather than appending a second. The digest covers SpcIndirectDataContent's value, not its SEQUENCE header, as Authenticode readers check it. - sign.certificate (a .pfx, NSGO_CERTIFICATE_PASSWORD) signs the executable, the command companion, the resources' PE images that carry no signature, and the installer. sign.sign_command signs them with a tool of its own, %1 standing for the path, for a hardware token or a cloud service. sign.timestamp_url, DigiCert's unless "none", asks an RFC 3161 server for a token, which the signer carries as its unsigned attribute so the signature outlives the certificate. - The installer's uninstaller comes from makensis, so it signs through NSIS's !uninstfinalize running `nsgo sign-uninstaller` with the certificate in the environment; that needs NSIS 3.08, and without it the uninstaller stays unsigned. - -certificate, -sign-command and -timestamp-url replace the three from the command line. build refuses two ways of signing at once, a certificate on a build that names no Windows target, and it refuses a certificate outside a release build. Verified: the package's tests, including osslsigncode's verification of an image signed here, and a real build of examples/hello whose exe, setup and uninstaller each verify with osslsigncode. The MSIX stays unsigned: AppxSignature.p7x is a package signature of its own, recorded in the roadmap.
houko
pushed a commit
that referenced
this pull request
Nov 16, 2026
A Windows download that carries no signature, or one from a certificate SmartScreen does not know, warns the user before it opens. MyGo signs Windows packages; NSGo wrote them unsigned, and Windows code signing was a roadmap gap. Add it here without the Windows SDK, so a Mac signs what it builds: - internal package cmd/nsgo/authenticode signs a PE image: it parses the headers, computes the Authenticode digest (headers without the checksum and certificate table entry, every section in file order, the bytes between and after them, a short last block padded to 8 bytes), writes a WIN_CERTIFICATE holding a PKCS #7 SignedData over SpcIndirectDataContent and recomputes the PE checksum. A re-signed image replaces the old signature rather than appending a second. The digest covers SpcIndirectDataContent's value, not its SEQUENCE header, as Authenticode readers check it. - sign.certificate (a .pfx, NSGO_CERTIFICATE_PASSWORD) signs the executable, the command companion, the resources' PE images that carry no signature, and the installer. sign.sign_command signs them with a tool of its own, %1 standing for the path, for a hardware token or a cloud service. sign.timestamp_url, DigiCert's unless "none", asks an RFC 3161 server for a token, which the signer carries as its unsigned attribute so the signature outlives the certificate. - The installer's uninstaller comes from makensis, so it signs through NSIS's !uninstfinalize running `nsgo sign-uninstaller` with the certificate in the environment; that needs NSIS 3.08, and without it the uninstaller stays unsigned. - -certificate, -sign-command and -timestamp-url replace the three from the command line. build refuses two ways of signing at once, a certificate on a build that names no Windows target, and it refuses a certificate outside a release build. Verified: the package's tests, including osslsigncode's verification of an image signed here, and a real build of examples/hello whose exe, setup and uninstaller each verify with osslsigncode. The MSIX stays unsigned: AppxSignature.p7x is a package signature of its own, recorded in the roadmap.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two allocations that a moving screen pays once and then keeps.
1. The first commit's item buffer stays the tree's capacity.
Tree.itemsis the queue a commit builds. The first commit sends every view, so the
slice grows to the whole tree — 14 892 items × 368 B for a 400-row table —
while a steady commit queues tens of items. It is reset with
[:0], whichkeeps the capacity, so the peak is pinned for the life of the tree. Give it
back once the queue is small again, with a floor and a ratio guard so it
does not thrash.
2.
node.dynheld a Style for every node. It stored a fullStyle(976 B) even for nodes without a
StyleFunc, and its render effectallocated a fresh one on every call. Keep a pointer, allocate it once, and
update it in place:
unsafe.Sizeof(node)drops 5696 → 4728 B.Neither changes the public API nor what a commit sends.
Numbers
macOS 26 (Apple M6, go1.27.1, 144 Hz). Same bench source (
bench/quotes),both binaries running at the same time so they see the same machine; CPU
from
ps -o cputime, memory fromfootprint.core.ScrollThe 40-row case barely moves, as expected: it is dominated by the macOS
base and the window's backing store. The buffer fix scales with the tree,
which is where it matters.
Tests
go test ./core— 147 passing, 0.5 s.Two new tests, each verified failing before the fix:
TestCommitBufferDropsTheFirstCommitPeak— reportsthe commit buffer kept its peak: cap 14892 -> 14892.TestStyleFuncKeepsOneStyle— asserts one allocation per node acrossrenders, and that a node without a
StyleFunckeeps none.I did not run the whole suite locally;
go test ./...takes about tenminutes here (
examples/cmd), so only./corewas run.