Skip to content

fix(compute): use -gc=precise for TinyGo default build command (#1480) - #1917

Closed
Tyagiquamar wants to merge 1 commit into
fastly:mainfrom
Tyagiquamar:fix/tinygo-precise-gc
Closed

Tyagiquamar wants to merge 1 commit into
fastly:mainfrom
Tyagiquamar:fix/tinygo-precise-gc

Conversation

@Tyagiquamar

@Tyagiquamar Tyagiquamar commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Change summary

Updates the default fallback build command for TinyGo in pkg/commands/compute/language_go.go from -gc=conservative to -gc=precise. The precise collector provides more accurate and efficient garbage collection in Wasm builds and avoids the memory corruption reported in #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?

Changes to Core Features:

  • Have you written new tests for your core changes, as applicable? No test file is changed in this PR.
  • Have you successfully run tests with your changes locally?

User Impact

TinyGo compute builds now default to the precise garbage collector, which fixes memory corruption in Wasm output. Users who need the old behavior can still pass -gc=conservative explicitly in their build command.

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

None; the change only alters the default fallback build command for TinyGo.

Verification

  • gofmt -l pkg/commands/compute/language_go.go (clean)
  • go test ./pkg/commands/compute/... in Docker golang:1.26-bookworm (all tests pass)

@Tyagiquamar
Tyagiquamar requested a review from a team as a code owner September 26, 2026 14:02
@Tyagiquamar
Tyagiquamar requested a review from rcaril September 26, 2026 14:02
@rcaril

rcaril commented Sep 28, 2026

Copy link
Copy Markdown
Member

Hi @Tyagiquamar - please use our PR template:

### Change summary

 <!--
Briefly describe the changes introduced in this pull request. Include context or
reasoning behind the changes, even if they seem minor. If relevant, link to any
related discussions (e.g. Slack threads, tickets, documents).
-->

All Submissions:

* [ ] Have you followed the guidelines in our Contributing document?
* [ ] Have you checked to ensure there aren't other open [Pull Requests](https://github.com/fastly/cli/pulls) for the same update/change?

<!-- You can erase any parts of this template not applicable to your Pull Request. -->

### 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

<!-- What is the user impact of this change? -->

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

<!-- Any breaking changes, etc -->

@Tyagiquamar

Copy link
Copy Markdown
Contributor Author

Updated the PR description to match the current template, including the Core Features section, while preserving the rationale, user impact, and validation details. No code changes.

@rcaril

rcaril commented Oct 2, 2026

Copy link
Copy Markdown
Member

Thanks for your contribution @Tyagiquamar. Hard-coding -gc=precise would break the fallback build for older TinyGo versions the CLI still supports. We are going to discuss alternate approaches internally before making any changes here. As such, I'm going to close this PR.

@rcaril rcaril closed this Oct 2, 2026
WhiteAbeLincoln added a commit that referenced this pull request Oct 2, 2026
…nd (#1926)

### 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](tinygo-org/tinygo@655075e)
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](https://github.com/fastly/compute-starter-kits/blob/5024939c7297c9705b5693193ec3cba1f2346b8b/starter-kits/go/tinygo/fastly.toml#L12)
already provides a build script which is identical to this change.

See PR #1917 and issue #1480.

Fixes #1480

All Submissions:

* [X] Have you followed the guidelines in our Contributing document?
* [X] Have you checked to ensure there aren't other open [Pull
Requests](https://github.com/fastly/cli/pulls) for the same
update/change?

<!-- You can erase any parts of this template not applicable to your
Pull Request. -->

### New Feature Submissions:

* [X] Does your submission pass tests?

### Changes to Core Features:

* [X] Have you written new tests for your core changes, as applicable?
* [X] 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?

<!-- Any breaking changes, etc -->
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)

2 participants