Repository navigation
Speed up the IR evaluator and build releases with opt-level 3 - #19628
Merged
Merged
Conversation
- Register writes no longer allocate: the exit-status list only gets an entry for an external's output. - `binary_op` computes on the operand values in their registers and writes the result in place; literal and variable loads, `span` and `collect_reg` update registers in place too. - The compiler leaves out the `load-literal` + `drain` pair after an assignment or `let` used as a statement, unless a jump lands on the drain. - Custom command calls lend the caller's variables to the callee's parent stack and take them back afterwards, instead of cloning the whole caller stack. Closure calls copy only the variables. Argument normalization returns early when there is nothing to rewrite, and `NU_BACKTRACE` is looked up only when needed. - Release builds use `opt-level = 3` instead of "s".
- `drain_statement` checked for a jump target by scanning every label in the block, so compiling a block with many branches got quadratic. It now compares against the highest label target, which the builder tracks as labels are set. - `Stack::lend_vars` returns a guard that gives the variables back to the caller when it drops. Before, a panic in the callee that the caller caught (as the completion menu does) left the caller's stack with no variables. - Update the `drain_statement` docs and the `loop`/`while`/`for` pseudocode for the skipped drain.
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.
Description
Scripts that loop, do arithmetic or call custom commands spent most of their time on evaluator bookkeeping. This PR cuts most of it:
PipelineExecutionDatafilled its exit-status list withvec![None]for every value. Now only an external's output adds an entry.binary_opruns on the operands in their registers and writes the result in place. Literal loads, variable loads,spanandcollect_regalso write in place.load-literal+drainpair after an assignment orletused as a statement, since neither instruction did anything. The drain stays when a jump lands on it, because a value from another branch still needs draining there.scope variablesreads, was a clone of the whole caller stack on every call. Custom command calls now lend the caller's variables to it and take them back afterwards. Closure calls copy only the variables. Argument normalization and theNU_BACKTRACElookup are skipped when they have nothing to do.opt-level = 3instead of"s".Before and after
mainis bc405a2 with its release profile. The scripts come from shellarena, and the 100x rows run 100 times the iterations. Measured on macOS arm64. Wall time is from hyperfine with the load average under 3, and instructions retired are the median of 3 runs.Startup didn't change, so short scripts gain less.
opt-level = 3alone cuts instructions by 6-8%, and it growsnufrom 81.1 MB to 89.9 MB. Plugins use the same profile, so they grow too. I didn't measure them.view irfor the arith script drops from 58 to 46 instructions. The firstmutand the end of the loop:User-facing changes (Release notes)
view irno longer shows aload-literal+drainpair after an assignment orletused as a statement.nuis about 11% larger.Additional notes