perf(compiler): join the lines of the C sixteen at a time #213
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/205-sized-join"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #205
emittedText(compiler/src/backend/c/emission.trb) andtextOf(compiler/src/backend/c/units.trb) joined the lines of the C withlines.joined(separator: "\n") + "\n":concatenatedmerges neighbours pairwise inlog2 nlevels (about 21 for the compiler's own C), and the+ "\n"copies the whole text once more.Both now call
linesText, local to the C back end: sixteen lines, each followed by its newline, go into one piece through one"""interpolation (oneTextConcat, one allocation), and then sixteen pieces at a time through one interpolation, so every byte is copied once per level oflog16 nlevels (about 6). This is option 2 of the issue, as the loop decided: no new native, no change tostd, so no seed step, and the C of every other program stays as it is.The text is the same byte for byte: checked against
joined(separator: "\n") + "\n"for 0, 1, 15, 16, 17, 255, 256, 257, 4095, 4096, 4097 and 5000 lines in the VM; the emitted C ofmain's binary and this branch's binary is compared in CI (below).torb format --checkandtorb linton the two files: clean;torb check compiler: no problems.Test:
compiler/tests/lines-text.test.trbcompareslinesTextwithlines.joined(separator: "\n") + "\n"for 0, 1, 2, 15, 16, 17, 31, 32, 33, 255, 256, 257, 4095, 4096, 4097 and 5000 lines (the empty list, the tail loop, a partial last piece, exactly one full level of 16 pieces), and checks the single trailing newline.Emitted C: identical for
main's binary and this binary (52 files: compiler onlinux-x64andwindows-x64, five conformance programs,tools/release-sync), runmeasure-205on the throwaway branchloop/205-measure(forge CI).Measurement (same run; alternating
main/PR binaries, 3 runs, mean processor time):torb build --emit-c ./compiler29.51 s -> 27.07 s (1.09x, 29.65/29.69/29.20 -> 27.18/27.01/27.01);torb check compiler4.31 -> 4.40 s,checkadts 0.60 -> 0.63 s,build --emit-cadts 0.65 -> 0.68 s (within noise, these do not emit C of any size). Recorded indocs/PERFORMANCE.md9.9.Reviewed head
94c6b47. CI is green for this head, including "every host emits the same C", and the change is correct as far as I can read it.linesTextyields the bytes ofjoined("\n") + "\n"for 0 lines ("\n"), 1 to 15 (tail loop), and 16 or more (16-line pieces, then 16-piece merges).sixteenPiecespads past the end with"". Scope matches #205 option 2, with no native and no std change. Two blockers remain.[blocker] Tests:
linesTexthas no committed test. The PR body says the 0/1/15/16/17/255/256/257/4095/4096/4097/5000-line cases were checked "in the VM", but nothing in the diff keeps them. The existingemittedTexttests (compiler/tests/units.test.trb) use small programs only, and the CI hash comparison covers just the lengths of the emitted C that CI happens to produce. The boundaries are where this code can go wrong: a partial last piece, a level of exactly 16 pieces, and the empty list. Add a test (for example incompiler/tests/units.test.trbor a newemissiontest file) that compareslinesTextwithlines.joined(separator: "\n") + "\n"for those lengths.[blocker] Acceptance criteria of #205: "
torb build --emit-c ./compileris faster in the alternating-run comparison" and "Before/after numbers go into PERFORMANCE.md" are not met on this head.docs/PERFORMANCE.mdhas no 9.8, and the PR text defers the numbers to "a follow-up commit on this branch". The branch has one commit, so the follow-up is not there, and merging this head would close #205 without them. Push the measurement (or, if the gain is below noise, say so there, as the issue allows) together with the test from item 1, and request review on the new head.Non-blocking: none.
CI red on
41dacca:ci / tier A (linux-x64)(and the aggregategates) - theformat --checkgate fails:./compiler/tests/lines-text.test.trb"would change" (1 of 1144 files). Runtorb formaton that file and push; my review of the new head follows once CI is green.Reviewed head
f0ade81. My two earlier blockers (94c6b47) are fixed:compiler/tests/lines-text.test.trbpinslinesTextagainstjoined(separator: "\n") + "\n"at 0, 1, 2, 15, 16, 17, 31-33, 255-257, 4095-4097 and 5000 lines, anddocs/PERFORMANCE.mdhas the before/after numbers (build --emit-c ./compiler29.51 s -> 27.07 s). The code is correct as far as I can read it and the scope matches #205 option 2. Two blockers remain, and one rebase fixes both.[blocker] CI red:
ci / commit messagesfails onf0ade81(style(compiler): format lines-text.test.trb).tools/check-commits.shallows only feat, fix, perf, refactor, docs, test, build, ci, chore and revert, sostyleis refused. I reproduced it locally:f0ade81: not a Conventional Commit. The other jobs, includinggates, are green. Fold the formatting fix into41daccainstead of keeping it as its own commit, and do not usestyle:.[blocker] Not mergeable: main moved by 6 commits (
95ac043) anddocs/PERFORMANCE.mdconflicts (git merge-treereports a content conflict). Main already has a section### 9.8 The files of a program, parsed in parallel(6d4c2f8), so this PR's section also has to be renumbered to 9.9. Rebase onto main, then rename every reference to this section: the heading,(sixteen at a time, 9.8)in 9.6, thedocs/PERFORMANCE.md 9.8mentions inlinesText's doc comment and in the test header, and the PR body.After the rebase CI has to run again on the new head. Please request review on it.
Non-blocking: none.
f0ade8195ae83c2f3fffCI red on
e83c2f3:ci / tier B (linux-x64)(failing after 9m28s) and the aggregategates. All other jobs are green, including tier A,every host emits the same Cand the commit-message and pdisc checks. I could not read the tier B log through the API. The same job is also red on main (95ac043, push, failing after 9m5s), so it may not come from this change; please confirm from the log whether it fails in a test this PR touches. If it is the same failure as on main, say so here and fix or rerun it there. My review of this head follows once CI is green.test_io_a_cancelled_wait_releases_its_registrationleaks a block #218Checked the Actions log of
ci / tier B (linux-x64)one83c2f3: only theruntime testslane is red, withtests/io_test.c:301: torb_network_operations_alive(): 2, expected 1/test_io_a_cancelled_wait_releases_its_registration: 2 blocks leaked(234 tests, 1 failed). The conformance suite, the VM suite and the native tests of tier B pass. The same failure, byte for byte, is in the log of main95ac043(run 352, 19:12 UTC) and in a run from 01:42 UTC today, so it predates this PR. This PR changes onlycompiler/src/backend/c/emission.trb,units.trb,compiler/tests/lines-text.test.trbanddocs/PERFORMANCE.md, nothing under the runtime. Tracked as torbscript/language#218 (fix belongs there, not in this PR); tier A,every host emits the same C, commit messages and pdisc are green on this head. Re-requesting review.Reviewed head
e83c2f3(rebased onto main95ac043; my earlier blockers are fixed: commit messages and pdisc green, the section is 9.9 everywhere, PERFORMANCE.md merges cleanly).compiler/tests/lines-text.test.trbpinslinesTextagainstjoined(separator: "\n") + "\n"at 0, 1, 2, 15-17, 31-33, 255-257, 4095-4097 and 5000 lines. Tier A is green.every host emits the same Cis green (52 files identical).tier B (linux-x64)and the aggregategatesare red. I checked that this is not from this change: main95ac043shows the same two jobs red, the failing lane is the runtime testtest_io_a_cancelled_wait_releases_its_registration(tests/io_test.c:301), and the PR touches nothing under the runtime. It is tracked in #218. Approving on that basis; every job that can see this change is green.Non-blocking: none.