-
Notifications
You must be signed in to change notification settings - Fork 482
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
base: master
Are you sure you want to change the base?
Conversation
({cpu: 432732134016 | ||
| mem: 1722650147}) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The semantics change.
There was a problem hiding this 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.
There was a problem hiding this 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
({cpu: 5476180 | ||
| mem: 28020}) No newline at end of file | ||
({cpu: 5428180 | ||
| mem: 27720}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small
({cpu: 6684432 | ||
| mem: 33922}) No newline at end of file | ||
({cpu: 6636432 | ||
| mem: 33622}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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](https://private-user-images.githubusercontent.com/10480926/412395113-77d634ad-58ea-41f9-99ef-6f79a3e3782f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MDYzNzQsIm5iZiI6MTczOTYwNjA3NCwicGF0aCI6Ii8xMDQ4MDkyNi80MTIzOTUxMTMtNzdkNjM0YWQtNThlYS00MWY5LTk5ZWYtNmY3OWEzZTM3ODJmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE1VDA3NTQzNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTliYmYyY2JlN2RhNTdhNGY5NGM0ZjA1N2VhYzVhMTkyNzlhYTMwNWRlY2E0N2E1ZGU1ZjFkZmQ2MjkwNzQxYWUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.ymL5Mx5Vy4tYhQ3xW2hHEN_9LGiXcCsZMJZKflQkUK8)
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.