Commit d0d65581
d0d65581a374Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
gc: keep frozen heap strings immortal instead of marking them in the hot path
The #1449 fix marked a reachable frozen string 0xf1 -> 0xf0 inside sp_mark_string, but that inline is on optcarrot's GC mark path and is layout-sensitive: the extra branch cost ~19 fps (same generated optcarrot C, header-only A/B). Restore sp_mark_string to its original 0xfe -> 0xfc form and instead keep every frozen heap string (0xf1) across sp_str_sweep -- a live frozen global still survives (the #1449 UAF stays fixed, ASAN clean), and frozen literal constants are immortal anyway. The cost is that a rare dynamically-frozen-then-dropped string is no longer reclaimed, which is a good trade for the hot-path recovery.
make test 999 / make bench 57 / optcarrot checksum 59662, fps back to the pre-promote ~700 level.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- d0d65581a374
- Parent
- 7c6cb277a731
lib/sp_gc.hmodifiedView file
* String tag bytes: 0xfe heap-unmarked -> 0xfc marked; others skipped. */static inline void sp_mark_string(const char *s) { if (!s) return; unsigned char m = (unsigned char)s[-1]; if (m == 0xfe) ((char *)s)[-1] = (char)0xfc; /* A heap string frozen by .freeze (0xf1) lives on the sweepable string heap too; give it a reachable-this-cycle state (0xf0) so sp_str_sweep keeps it while rooted instead of freeing a live frozen global (#1449). */ else if (m == 0xf1) ((char *)s)[-1] = (char)0xf0; if ((unsigned char)s[-1] == 0xfe) { ((char *)s)[-1] = (char)0xfc; } /* No frozen (0xf1) branch here: this is inlined into optcarrot's GC mark and is layout-sensitive. A live frozen heap string is kept immortal by sp_str_sweep instead (#1449). */}static inline void sp_mark_rbval(sp_RbVal v) { if (v.tag == SP_TAG_STR) sp_mark_string(v.v.s);lib/sp_runtime.hmodifiedView file
Loading diff…