Repository navigation
@owned on core.os.d.ts's string functions: toFixed and Date strings stop leaking under rc - #107
Merged
Merged
Conversation
… stop leaking under rc convertNumber, convertInteger, timestamp_to_string, time_to_string, time_format and time_format_locale each return `s`, a view of their local char[]. Under rc a view a function returns is copied at the return (#481), so each hands its caller a string of its own at +1. Unmarked, they were C functions to lib.ts: the caller copied the result again and never gave back the function's own string - one leaked per `toFixed`, `toExponential`, `toPrecision`, `Date.toString`, `toISOString` call. 1M `(i + 0.5).toFixed(2)`: 34.4 MB -> 5.8 MB, flat. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Marks
core/core.os.d.ts's six string functions@owned:convertNumber,convertInteger,timestamp_to_string,time_to_string,time_format,time_format_locale.Each returns
s, a view of a localchar[]. Under rc the compiler copies a returned view at thereturn(#481), so the caller receives a string it owns. Left unmarked, they looked like C functions tolib.ts: the caller copied the result a second time and never released the function's own string. That leaked one string pertoFixed,toExponential,toPrecision,Date.toStringandtoISOStringcall. #106 left them unmarked on the wrong assumption that they return a pointer into a buffer.Measured (
-mm=rc):(i + 0.5).toFixed(2)DatetoString/toISOString/toExponential/toPrecision, 300KTests:
tests.ps1release (compile + JIT) passes in gc, rc, none and own. No compiler change is needed. The companion compiler PR (spread arguments passed to rest parameters, which fixesArray.join) was tested together with this branch.🤖 Generated with Claude Code