Skip to content

feat(#4752): implement sprintf in pure EO#5271

Draft
asmirnov-backend wants to merge 4 commits into
objectionary:masterfrom
asmirnov-backend:4752-pure-eo-sprintf
Draft

feat(#4752): implement sprintf in pure EO#5271
asmirnov-backend wants to merge 4 commits into
objectionary:masterfrom
asmirnov-backend:4752-pure-eo-sprintf

Conversation

@asmirnov-backend

@asmirnov-backend asmirnov-backend commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Part #4752.

Reimplements tt.sprintf in pure EO (was a JVM/Node atom), supporting %s %d %f %x %b and positional %N$x references.

walk iterates over format.as-bytes using the native bytes.size/bytes.slice atoms rather than the recursive string.length/string.slice (which would make formatting O(n²) in allocation and exhaust the heap under the parallel test suite). % (0x25) never occurs inside a UTF-8 multi-byte sequence, so literal bytes copy through unchanged.

Number/bytes rendering is delegated to the reusable converters from #5272 (as-decimal, as-fixed, as-hex), so sprintf keeps only its parser and specifier dispatch.

The old Java atom is renamed to EOsprintfDeprecated to avoid a class-name clash with the transpiler-generated EOsprintf; a @todo puzzle tracks removing it (plus SprintfArgs and its test) in a follow-up.

EO tests cover all specifiers, positional refs, float truncation/padding, and error paths.

@github-actions

github-actions Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

🚀 Performance Analysis

All benchmarks are within the acceptable range. No critical degradation detected (threshold is 100%). Please refer to the detailed report for more information.

Click to see the detailed report
Test Base Score PR Score Change % Change Unit Mode
benchmarks.XmirBench.xmirToEO 9544.525 9843.999 299.474 3.14% ms/op Average Time

⚠️ Performance loss: benchmarks.XmirBench.xmirToEO is slower by 299.474 ms/op (3.14%)

asmirnov-backend and others added 3 commits July 1, 2026 12:42
Replace the JVM/Node atom with a pure-EO `tt.sprintf` that formats
%s, %d, %f, %x, %b and positional `%N$x` references, building the
result from bytes via `tt.as-ascii` and `tt.is-digit`. The old Java
atom is renamed to `EOsprintfDeprecated` to dodge a class-name clash
with the transpiler-generated `EOsprintf`; a puzzle tracks removing it
(plus `SprintfArgs` and its test) in a follow-up.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Replace the inline decimal, fixed-point and hexadecimal formatters with
the reusable `as-decimal`, `as-fixed` and `as-hex` objects, leaving
sprintf with only its parser and specifier dispatch.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…blowup

The pure-EO `walk` re-derived `format.length` and `format.slice` on
every step, and both are recursive pure-EO objects, so formatting was
O(n^2) in recursive-object allocation. Under the full parallel test
suite this exhausted the 4G heap and sent the JVM into a GC death
spiral: `EOsprintfTest` ran 5+ hours and OOMed, blowing the 6h CI cap.

Hoist `format.as-bytes` and its `size` once and walk the raw bytes with
the native `bytes.size`/`bytes.slice` atoms instead. `%` (0x25) never
occurs inside a UTF-8 multi-byte sequence, so literal bytes copy through
unchanged. The suite now runs 1371 tests with no OOM; `EOsprintfTest`
drops from ~18s to ~1.3s and fits well under 256M.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@asmirnov-backend asmirnov-backend marked this pull request as ready for review July 1, 2026 09:59
@asmirnov-backend

Copy link
Copy Markdown
Contributor Author

@yegor256, could you please take a look

@yegor256

yegor256 commented Jul 1, 2026

Copy link
Copy Markdown
Member

@asmirnov-backend just delete EOsprintfDeprecated.java file. why do we need it in the repo?

Delete EOsprintfDeprecated, SprintfArgs, and SprintfArgsTest now that
tt.sprintf is implemented in pure EO.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Jul 1, 2026

Copy link
Copy Markdown

@asmirnov-backend

Copy link
Copy Markdown
Contributor Author

@yegor256 thanks, deleted EOsprintfDeprecated.java. I'd originally deprecated it plus left a puzzle to avoid too many hits-of-code in one PR

@asmirnov-backend asmirnov-backend marked this pull request as draft July 1, 2026 16:17
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