Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Optimization] Make Z inline better #6839

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

effectfully
Copy link
Contributor

@effectfully effectfully commented Feb 12, 2025

This makes Z inline better, if it's already getting inlined. I.e. if it's already getting inlined, we get a speedup with this PR (and a bit less size consumed), otherwise we get a slowdown (and a bit more size consumed).

If we're gonna start always inlining Z, this is likely beneficial, otherwise not.

The idea is simple: eta-expand Z, so that inlining the stepper function gives us back a value (rather than an application) which can be inlined further. The gist of the change:
image

This partially cancels what #5939 did and reintroduces the strictness issue that that PR fixed, which is probably not good, but I dunno.

It'd probably be best to just mark fix as inlinable, since we generate it ourselves anyway and can do it. Then we won't need to rely on it being defined a certain way.

@effectfully effectfully added Do not merge EXPERIMENT Experiments that we probably don't want to merge No Changelog Required Add this to skip the Changelog Check optimization labels Feb 12, 2025
@effectfully effectfully requested a review from zliu41 February 12, 2025 11:18
@effectfully effectfully self-assigned this Feb 12, 2025
({cpu: 432732134016
| mem: 1722650147})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm rather puzzled as to how eta-expanding Z leads to such a massive slowdown.

1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The semantics change.

Copy link
Member

@zliu41 zliu41 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to work as expected? Z is already (unconditionally) inlined if it is only used once, which should be the case in a number of test cases. But I'm not seeing any cost reduction.

Copy link
Contributor Author

@effectfully effectfully left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a couple of examples

Comment on lines 0 to 2
({cpu: 5476180
| mem: 28020}) No newline at end of file
({cpu: 5428180
| mem: 27720})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small

Comment on lines 0 to 2
({cpu: 6684432
| mem: 33922}) No newline at end of file
({cpu: 6636432
| mem: 33622})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small

Copy link
Member

@zliu41 zliu41 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The results in #6842 looks great. I've merged #6841, so you can rebase and merge this now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Do not merge EXPERIMENT Experiments that we probably don't want to merge No Changelog Required Add this to skip the Changelog Check optimization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants