Skip to content

fix(compute): remove hardcoded -gc flag from the tinygo build command - #1926

Merged
WhiteAbeLincoln merged 3 commits into
mainfrom
abe/CDTOOL-1785-tinygo-gc
Oct 2, 2026
Merged

WhiteAbeLincoln merged 3 commits into
mainfrom
abe/CDTOOL-1785-tinygo-gc

Conversation

@WhiteAbeLincoln

@WhiteAbeLincoln WhiteAbeLincoln commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Change summary

For tinygo binaries before version 0.34, the default is -gc=conservative. version 0.34 swapped the default to precise. Dropping the gc flag completely preserves the current behavior for users on older tinygo versions, and switches to the precise collector for newer tinygo.

When benchmarked within viceroy, the change generally results in a faster binary and the same memory usage, but under some workloads (that allocate lots of small pointer-heavy objects) the peak memory usage can be higher. The reason seems to be explained by the commit message that introduces the collector, which says “It does however use a bit more RAM to store the layout of each object”.

Workloads which care about memory usage more than execution speed can revert this change by adding a build script to their fastly.toml: build = "tinygo build -target=wasi -gc=conservative -o bin/main.wasm ./"

Also note that this change only affects users who do not currently have a build script in their fastly.toml file. The current tinygo starter kit already provides a build script which is identical to this change.

See PR #1917 and issue #1480.

Fixes #1480

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  • Does your submission pass tests?

Changes to Core Features:

  • Have you written new tests for your core changes, as applicable?
  • Have you successfully run tests with your changes locally?

User Impact

Changes the collector used to precise for users of tinygo>=0.34

Are there any considerations that need to be addressed for release?

@WhiteAbeLincoln
WhiteAbeLincoln requested a review from a team as a code owner October 2, 2026 16:44
@WhiteAbeLincoln
WhiteAbeLincoln requested a review from rcaril October 2, 2026 16:44
Comment thread CHANGELOG.md Resolved
For tinygo binaries before version 0.34, the default is
`-gc=conservative`. version 0.34 swapped the default to precise.
Dropping the gc flag completely preserves the current behavior for users
on older tinygo versions, and switches to the precise collector for
newer tinygo.

When benchmarked within viceroy, the change generally results in a
faster binary and the same memory usage, but under some workloads (that
allocate lots of small pointer-heavy objects) the peak memory usage can
be higher. The reason seems to be explained by the commit message that
introduces the collector, which says “It does however use a bit more RAM
to store the layout of each object”.

Workloads which care about memory usage more than execution speed can
revert this change by adding a build script to their `fastly.toml`:
`build = "tinygo build -target=wasi -gc=conservative -o bin/main.wasm
./"`
@WhiteAbeLincoln
WhiteAbeLincoln force-pushed the abe/CDTOOL-1785-tinygo-gc branch from c8dd090 to 846837d Compare October 2, 2026 16:48
@WhiteAbeLincoln WhiteAbeLincoln changed the title feat(compute): remove hardcoded -gc flag from the tinygo build command fix(compute): remove hardcoded -gc flag from the tinygo build command Oct 2, 2026

@rcaril rcaril left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for the clear explanation!

Should we consider adding a test scenario to TestBuildGo with no [script] block to exercise the TinyGo fallback?

@WhiteAbeLincoln

Copy link
Copy Markdown
Contributor Author

Looks good, thanks for the clear explanation!

Should we consider adding a test scenario to TestBuildGo with no [script] block to exercise the TinyGo fallback?

It looks like CI still installs tinygo 0.31.2, so the default will still be conservative. A test that checks the fallback is still useful though.

@kpfleming

Copy link
Copy Markdown
Member

Please keep in mind that our starter kit (https://github.com/fastly/compute-starter-kits/blob/5024939c7297c9705b5693193ec3cba1f2346b8b/starter-kits/go/tinygo/fastly.toml#L12) specifies the build command directly and doesn't include this flag, so this change in the CLI will only affect users who built their project using an older starter kit or have removed the build command from fastly.toml.

@WhiteAbeLincoln

Copy link
Copy Markdown
Contributor Author

Please keep in mind that our starter kit (https://github.com/fastly/compute-starter-kits/blob/5024939c7297c9705b5693193ec3cba1f2346b8b/starter-kits/go/tinygo/fastly.toml#L12) specifies the build command directly and doesn't include this flag, so this change in the CLI will only affect users who built their project using an older starter kit or have removed the build command from fastly.toml.

It looks like the starter kit already excludes the -gc flag, so this is probably another reason to make the change!

@rcaril rcaril left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@WhiteAbeLincoln
WhiteAbeLincoln enabled auto-merge (squash) October 2, 2026 17:00
@WhiteAbeLincoln

Copy link
Copy Markdown
Contributor Author

So it turns out we didn't have any tests which used tinygo prior to the one I just added. I had run the new tests locally but I was on 0.42. The 0.31.2 version installed by CI complained that it couldn't be used alongside go 1.26.x also installed by CI, which showed up with this change because tinygo was actually called in a test. I've bumped the CI version to account for this.

@WhiteAbeLincoln
WhiteAbeLincoln merged commit d8992b7 into main Oct 2, 2026
13 checks passed
@WhiteAbeLincoln
WhiteAbeLincoln deleted the abe/CDTOOL-1785-tinygo-gc branch October 2, 2026 17:20
@dgryski

dgryski commented Oct 2, 2026

Copy link
Copy Markdown
Member

👍 The precise collector is much better than the conservative one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TinyGo should use -gc=precise (or have nothing and just use the default provided by tinygo)

4 participants