Skip to content

runtime: add MemStats.NumGC for API compatibility - #5590

Open
0pcom wants to merge 1 commit into
tinygo-org:devfrom
0magnet:runtime-numgc
Open

runtime: add MemStats.NumGC for API compatibility#5590
0pcom wants to merge 1 commit into
tinygo-org:devfrom
0magnet:runtime-numgc

Conversation

@0pcom

@0pcom 0pcom commented Aug 14, 2026

Copy link
Copy Markdown

runtime.MemStats is missing NumGC, so any program that reads it fails to compile — including programs that only log it.

TinyGo's GC does not count cycles, so the field stays 0 and the doc comment says exactly that rather than implying a number nobody maintains. The same approach the struct already takes for other fields it cannot fill.

Verified by building TinyGo.

TinyGo's GC does not count cycles, so this stays 0 and says so. It exists
because reading runtime.MemStats.NumGC is common enough in dependency
code that its absence is a compile error for programs that never look at
the value.

@b0ch3nski b0ch3nski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@dgryski

dgryski commented Aug 14, 2026

Copy link
Copy Markdown
Member

Normally when we add fields to runtime.MemStats, we try to implement them for the garbage collectors where possible. Could you add a gcNumGC int to gc_blocks.go (here https://github.com/tinygo-org/tinygo/blob/dev/src/runtime/gc_blocks.go#L59 ) and track the number of garbage collections? For boehmgc, it's the gc_no field of the returned prof_stats struct.

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.

3 participants