Skip to content

Conversation

@evantypanski
Copy link
Contributor

@evantypanski evantypanski commented Dec 12, 2025

Supersedes #2173 (see #2173 (comment))

Closes #2031

Draft to get benchmark run, then I'll clean it up and fix bugs/tests if it's worth it. and add the explanation for all of the weirdness in here

EDIT: Seems like the perf improvement will be worth it, I'll clean this up.

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 12, 2025

CodSpeed Performance Report

Merging #2228 will improve performances by 12.42%

Comparing topic/etyp/propagate-function-returns-try2 (9b53517) with main (d3fe866)

Summary

⚡ 4 improvements
✅ 24 untouched

Benchmarks breakdown

Benchmark BASE HEAD Change
UnitVectorSize][10000] 12.3 ms 11 ms +10.97%
UnitVectorSize][1000] 1.2 ms 1.1 ms +10.87%
UnitVectorSize][100000] 129.8 ms 115.4 ms +12.42%
UnitVectorSize][100] 157.4 µs 144.6 µs +8.91%

@evantypanski evantypanski force-pushed the topic/etyp/propagate-function-returns-try2 branch from d13a715 to 7d54fa5 Compare December 12, 2025 19:16
@evantypanski
Copy link
Contributor Author

evantypanski commented Dec 12, 2025

I just rebased this on #2229 which makes the size benchmark only use size (and no lookahead), which means this pass removes those. That ends up being a 10-12% improvement over current main, but that change itself slowed the parsers down, so this is more like 14-15%, I think.

Note that I changed it to be different so that the lookahead and size benchmarks test different things. I noticed both removed the same parameters, and every other time I've seen them they've moved in unison, so I think it's fair to separate their concerns a bit. It's just a bit nice to see bigger number too :)

EDIT: And honestly I don't think the 6% improvement in lookahead is shabby either!

end-to-end improvement in Zeek with the SSL analyzer:

$ hyperfine "~/.local/zeek/bin/zeek -Cr out.trace" "~/.local/zeek-funcrets/bin/zeek -Cr out.trace" --warmup 3
Benchmark 1: ~/.local/zeek/bin/zeek -Cr out.trace
  Time (mean ± σ):      1.566 s ±  0.009 s    [User: 1.486 s, System: 0.118 s]
  Range (min … max):    1.556 s …  1.584 s    10 runs

Benchmark 2: ~/.local/zeek-funcrets/bin/zeek -Cr out.trace
  Time (mean ± σ):      1.521 s ±  0.009 s    [User: 1.439 s, System: 0.121 s]
  Range (min … max):    1.507 s …  1.543 s    10 runs

Summary
  ~/.local/zeek-funcrets/bin/zeek -Cr out.trace ran
    1.03 ± 0.01 times faster than ~/.local/zeek/bin/zeek -Cr out.trace

If I remember right the Spicy parts were about 1/2 the total runtime so this is about the same as the lookahead benchmark improvements

After 5197e79, we replace some declarations with the RHS of the
assignment so that we don't remove method calls. The same problem applies
to assignments generally, so add cases for those.

This also makes some code stick around (particularly when paired with
constant propagation), so we need more aggressive removal of expressions
whose result is unused and who don't have side effects.
This is necessary to be separate from the statement/declaration tracking
since there are more cases of just "floating" expression statements,
like `(a, b, c, d)` after some constant propagation and dead code
elimination.
Since the two benchmarks used the same `Inner`, they would get the same
interprocedural optimizations. This doesn't give the full picture about
how something changes, so separate them so that we can get a better
picture.

This definitely makes the benchmarks more "micro," but I believe that we
see more people using *either* lookahead *or* size, not both on the same
unit.
This will propagate the `result` variable in cases like:

```
result = my_method_call();
return result;
```

into:

```
return my_method_call();
```
@evantypanski evantypanski force-pushed the topic/etyp/propagate-function-returns-try2 branch from f30f2e6 to 9b53517 Compare December 17, 2025 19:47
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.

Propagate constants through function returns

2 participants