Skip to content

Reduce Go garbage collection aggressiveness#97

Merged
oskarszoon merged 3 commits into
bsv-blockchain:mainfrom
oskarszoon:feature/gogc
Nov 4, 2025
Merged

Reduce Go garbage collection aggressiveness#97
oskarszoon merged 3 commits into
bsv-blockchain:mainfrom
oskarszoon:feature/gogc

Conversation

@oskarszoon

@oskarszoon oskarszoon commented Nov 3, 2025

Copy link
Copy Markdown
Contributor

Reduces garbage collection frequency by setting GOGC=200, triggering GC when heap grows to 300% of previous live set (vs. default 200%). This reduces GC cycles by ~50% during high-throughput operations like block validation.

From a subtreevalidation profile during teratestnet sync:
1.39s 10.40% runtime.scanobject (GC scanning heap)
2.60s 19.45% runtime.gcAssistAlloc (goroutines helping GC)
4.32s 32.31% runtime.mallocgc (allocation + GC triggering)

Total GC overhead: ~6-7s out of 13.37s (45-50%)

GOGC=200 is conservative and we can probably increase in the future and make it configurable for specific deployments that have more memory available.

@github-actions

github-actions Bot commented Nov 3, 2025

Copy link
Copy Markdown
Contributor

🤖 Claude Code Review

Status: Complete


Current Review:

This PR makes a simple, well-justified performance optimization by reducing Go's garbage collection frequency. The change is:

  • Well-documented: Clear comments explain the rationale and override mechanism
  • Conservative: GOGC=200 is a reasonable starting point (balances memory vs GC overhead)
  • Flexible: Can be overridden at deployment time as noted in comments
  • Appropriate placement: Set in the runtime container image after build stage

The profiling data in the PR description shows meaningful GC overhead (45-50%) that this change addresses. Setting GOGC at the container level is a good approach since it applies globally to all services in the image without code changes.

No issues found.

@sonarqubecloud

sonarqubecloud Bot commented Nov 4, 2025

Copy link
Copy Markdown

@oskarszoon oskarszoon merged commit f516fc9 into bsv-blockchain:main Nov 4, 2025
9 checks passed
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.

2 participants