Repository navigation
perf(c): term_drop frees a node whose only box is its last field as it walks - #2151
Closed
nicolas-abril wants to merge 1 commit into
Closed
nicolas-abril wants to merge 1 commit into
nicolas-abril wants to merge 1 commit into
Conversation
…t walks A list of words (a String, a List<U32>, a chain of keys) was dropped through term_drop's general path: each node joined the cur chain, its fields were stepped one at a time, and it was freed on the way out. Such a node now goes at once: when every field but the last is trivial, the node is freed and the walk goes on with the last field. Order of frees is unchanged, and a shared cell met on the way goes through the count test at the top of the loop as before. hashmap, one thread, GPU off: 18.50G instructions to 16.71G on main; on top of bendlang#2135, 8.09G to 6.22G. tests/rfc/drop_list.bend spells the shapes around the new path. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Collaborator
Author
|
Moved to nicolas-abril#12, which keeps it saved off the main queue until it can be accepted. |
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.
comp.tsis 66,105 ttok, 105 over the 66,000 cap (main is 65,962; this adds 143), sorepo-gatefails until that is settled. Measured on one Mac (M4), not on the cluster: thetestandperfgates have not been run.Independent of #2135 and #2134: it branches from main and touches only
term_drop. It was found while breaking down whathashmapstill loses to its C twin on top of #2135, where the final drop of the table is half of the instructions left.What it does
term_dropwalks any value with one general loop: a node joins thecurchain, its fields are stepped one at a time, and it is freed on the way out. A list of words (aString, aList<U32>, a chain of keys) pays that for every node, over 100 instructions each.Now a constructor node whose fields are all trivial but the last is freed at once and the walk goes on with that last field, never touching
cur. The test is on the node's words at run time, so it holds for any type, and a node that fails it takes the general path as before. Nothing else changes:err_spunlike the general loop does.Results
One M4, one thread, GPU off. Instructions retired and cycles are the best of interleaved runs; the machine was shared with other benchmarks, so read the cycles as rough and the instructions as exact.
hashmapon main, instructionshashmapon main, its final drop alonehashmapon #2135, instructionshashmapon #2135, cycleshashmapon main, cycles (medians of 14 alternating runs, machine loaded)List<U32>of 1M and aStringof 1M chars built and dropped, 100 times: instructionsOn #2135 the chains in the table are no longer shared, so the drop is a larger part of what is left and the change is worth more there.
Bench suite: the runtime is part of every program's C, so all 17
bench/runtimeprograms were built with main and with this branch and run. Every one prints the same result.bfseditdistgameoflifehashmaphistogramkmeanslexermandelbrotmerklenbodyqueensraytracesymregterraintree-bitonictree-matmultree-radixNo program runs more than 0.13% more instructions (
merkle; a node that fails the new test still pays for the test). Cycles on this shared machine moved by several percent either way between runs of the same binary, so they are not listed;merklealternated six times gave 20.47G on main and 20.78G here at best, with overlapping spreads.Checks
All local, against main
011b54d3:-DBEND_POISONand a count of live heap words at exit: the same output and the same count as main on every one.tests/rfc/drop_list.benddrops a list of words, a chain of one-field nodes, a list whose item is a box in every other node, a list with its box first, a node that ends in an Array of lists, lists shared between two holders, and two heads over one shared tail. With poisoned frees and the live count it fails five wrong versions of the new path that I tried on it (any node taken as a list, a wrong size class, the last field read after the free, a shared tail taken as owned, a boxed first field skipped). It passes on the C lane, on Metal with its rounds called asround!, and inbend file.bend.hashmapand the new test run on the GPU and print the same results.repo.tsfails only on the ttok cap.Not covered
Cons{tail, head}) takes the general path as before.tscwas not run.What is left in
hashmapOn #2135 plus this,
hashmapis at about 6.2G instructions against the C twin's 3.2G. A drop written for the element type (free the chain's nodes in a plain loop) would take the drop from 2.24G to 0.63G instructions; the generic walk cannot get there, since it reads the constructor table and tests each field. That needs the type at the drop site and is not attempted here.🤖 Generated with Claude Code