Skip to content

Conversation

@ltratt
Copy link
Contributor

@ltratt ltratt commented Dec 28, 2025

While looking at profiles of the j2's compiler, I noticed an easy win, which this PR addresses: rstate_diff_to_action was taking lots of time, mostly because it malloced chunks of memory in cases where it didn't need to. Fixing this makes a small (~5%) improvement to compilation time.

This seems to allow rustc to generate better code, even though I had
assumed it wouldn't make any difference.
I think I'd originally had somewhat different code in these two loops,
but that has since disappeared, and there's no need -- indeed, it's
inefficient -- to have two loops.
`self_copies` served two purposes:

1. Telling us when register fills have changed.
2. recording that a register is used.

However, we don't make use of (2) yet, there are lots of cases where a
register is used and unchanged, and `RegCopy` is a heavy-weight struct.
All that means that we are putting a lot of values into `self_copies`
without deriving much benefit from doing so.

This commit recognises that we don't need to generate "fill changes" if
fills haven't changed or if the destination fill is `Undefined`. Doing
so saves about 5% of compilation of time, probably mostly because in
about 90% of cases we no longer `malloc` anything.
@Fidget-Spinner Fidget-Spinner added this pull request to the merge queue Dec 28, 2025
@Fidget-Spinner Fidget-Spinner removed this pull request from the merge queue due to a manual request Dec 28, 2025
@Fidget-Spinner
Copy link
Contributor

I forgot to ask if you would like to squash?

@ltratt
Copy link
Contributor Author

ltratt commented Dec 28, 2025

No thanks.

@Fidget-Spinner Fidget-Spinner added this pull request to the merge queue Dec 28, 2025
Merged via the queue into ykjit:master with commit d5a435d Dec 28, 2025
2 checks passed
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