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

Avoid copying IR nodes when no change is performed in passes #10839

Merged
merged 7 commits into from
Aug 21, 2024

Conversation

hubertp
Copy link
Collaborator

@hubertp hubertp commented Aug 16, 2024

Pull Request Description

This PR attempts to avoid creating unnecessary IR nodes. Whenever none of the components of any IR node is different from the original one, there is no need to create a new instance of it.

Renders #10718 obsolete.

Important Notes

I spent quite a lot of time debugging problems with this approach (compared to #10718) only to find out that the problem was in the overriden definition of MetadataStorage.equals, that prevented duplication from working correctly.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    TypeScript,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • Unit tests have been written where possible.

This PR ensures that we only perform IR copying when actually needed,
i.e. when one of the fields has changed.
Most of the changes should not be controversial except for equality
change in MetadataStorage. Without it, an empty pass metadata would be
treated as equal, therefore preventing duplication from happening.
@hubertp hubertp added the CI: No changelog needed Do not require a changelog entry for this PR. label Aug 16, 2024
@hubertp hubertp mentioned this pull request Aug 16, 2024
4 tasks
@JaroslavTulach
Copy link
Member

JaroslavTulach commented Aug 17, 2024

There is a runtime-parser test failure:

Same expected: org.enso.compiler.core.ir.Module<
Module(imports = List(), exports = List(), bindings = List(), location = None, passData = MetadataStorage[], diagnostics = DiagnosticStorage(diagnostics = List()), id = null)
> but was: org.enso.compiler.core.ir.Module<
Module(imports = List(), exports = List(), bindings = List(), location = None, passData = MetadataStorage[], diagnostics = DiagnosticStorage(diagnostics = List()), id = null)
>

as I discovered later this is probably due to difference of MetadataStorage and DiagnosticStorage, right?

Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

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

Magnificent work on the copy methods rewrite. They should have been generated... if we ever get to rewriting this to Java, please use annotation processor to generate these copy & co. methods.

@hubertp
Copy link
Collaborator Author

hubertp commented Aug 21, 2024

I can't get flamegraphs similar to #9236 (comment) working but I've noticed in our profiling that we do much less copying now. At the expense of more equality checks, so you give some and you take some.
But this PR has already grown a lot and it seems to be a step in a good direction.

@hubertp hubertp merged commit a65383a into develop Aug 21, 2024
41 checks passed
@hubertp hubertp deleted the wip/hubert/copying-opt-2 branch August 21, 2024 16:20
hubertp added a commit that referenced this pull request Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants