Stop linking testify into production binaries via testsignal - #1342
Open
e-yavuz-1 wants to merge 2 commits into
Open
Stop linking testify into production binaries via testsignal#1342e-yavuz-1 wants to merge 2 commits into
e-yavuz-1 wants to merge 2 commits into
Conversation
added 2 commits
August 4, 2026 23:15
`testsignal` is production code — its own doc comment says it's designed
to have "minimal impact on the production code that calls into it" — but
it imported `riversharedtest` for a single function, `WaitTimeout`.
Go initializes every imported package, so nothing in that graph can be
eliminated by the linker. The result is that testify, go-spew, goleak,
and yaml end up in every binary that uses River. Measured with
`go tool nm -size` on a minimal program importing `river` and
`riverdriver/riverpgxv5`:
github.com/stretchr/testify 18 symbols / 1168 bytes
github.com/davecgh/go-spew 11 symbols / 1312 bytes
go.uber.org/goleak 8 symbols / 896 bytes
gopkg.in/yaml 22 symbols / 4320 bytes
riversharedtest 13 symbols / 2248 bytes
`WaitTimeout` depends only on `os` and `time`, so move it to
`rivershared/util/testutil`, which `testsignal` already imports and which
has no dependencies outside the standard library. `riversharedtest.WaitTimeout`
stays as a wrapper so no public API changes, and its two internal callers,
`WaitOrTimeout` and `WaitOrTimeoutN`, are untouched. Its test moves
alongside the implementation.
After the move, the same program links no testify, go-spew, goleak, yaml,
or riversharedtest symbols at all: 951 fewer symbols and 957 KB less
binary.
Contributor
|
@e-yavuz-1 Dang great find. Do you think could sign our CLA? https://github.com/riverqueue/rivercla Otherwise, LGTM. |
Contributor
|
Also adding #1343 for a more structural fix by checking for this problem during linting. |
Author
|
@brandur CLA signed. |
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.
testsignalis production code — its own doc comment says it's designed to have "minimal impact on the production code that calls into it" — but it importedriversharedtestfor a single function,WaitTimeout.Go initializes every imported package, so nothing in that graph can be eliminated by the linker. The result is that testify, go-spew, goleak, and yaml end up in every binary that uses River. Measured with
go tool nm -sizeon a minimal program importingriverandriverdriver/riverpgxv5:WaitTimeoutdepends only onosandtime, so move it torivershared/util/testutil, whichtestsignalalready imports and which has no dependencies outside the standard library.riversharedtest.WaitTimeoutstays as a wrapper so no public API changes, and its two internal callers,WaitOrTimeoutandWaitOrTimeoutN, are untouched. Its test moves alongside the implementation.After the move, the same program links no testify, go-spew, goleak, yaml, or riversharedtest symbols at all: 951 fewer symbols and 957 KB less binary.