feat: conditional srand48/cs_time_ms startup calls + usesGC infrastructure#108
Merged
feat: conditional srand48/cs_time_ms startup calls + usesGC infrastructure#108
Conversation
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.
feat: conditional startup calls + usesGC infrastructure
Removes two unnecessary calls from binary startup and adds the flag infrastructure needed to eventually gate `GC_init()` + `-lgc`.
What changes
Conditional `srand48()` seeding
Every binary previously called `srand48()` at startup even when `Math.random()` was never used. Now only emitted when `Math.random()` is called.
Conditional `cs_time_ms()` call
`cs_time_ms()` was called unconditionally at startup (used by the test runner). Now only emitted when the test runner is active.
`usesGC` flag infrastructure
New `usesGC` flag on `LLVMGenerator` (and `usesMathRandom` which drives the `srand48` gate). These follow the existing pattern of `number` fields for self-hosting compatibility. The `usesGC` flag is the setup for a follow-up that gates `GC_init()` + `-lgc` — which is the only remaining source of startup overhead vs C.
What's NOT here
Bridge `.o` conditional linking was explored and reverted — the linker already dead-strips unused symbols from statically linked `.o` files, so gating them manually is redundant. The existing `usesHttpServer`, `usesCrypto`, `usesSqlite` flags that gate actual `.a`/`.so` libraries with init code are still valid and untouched.
Startup benchmark (hello world)
Gap is `GC_init()` — gating it requires tagging every `GC_malloc` emit site with `setUsesGC(true)`, then gating `GC_init()` and `-lgc` behind `usesGC`. That's the follow-up.
Implementation notes