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

fix(ssa): Track RC instructions when removing last loads #6682

Closed
wants to merge 4 commits into from

Conversation

vezenovm
Copy link
Contributor

@vezenovm vezenovm commented Dec 2, 2024

Description

Problem*

Resolves #6674

Summary*

This brings back code that was removed in #6019, but now for repeated loads rather than trivial stores. When analyzing instructions we check whether the last instruction was an inc_rc or a dec_rc. If it was, we do not remove the repeated load.

Needing to bring this back is very strange to me. Repeat loads are essentially "trivial loads" and an extra inc rc instruction as in #6674 (comment) should just cause our array to be copied rather than mutated. We should continue to try and get a small reproduction of the issue to understand it better and bring it into our test suite.

Another option is to simply revert #6088

Additional Context

Important information from the issue (#6674 (comment))

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@vezenovm vezenovm added the run-external-checks Trigger CI job to run tests on external repos label Dec 2, 2024
@vezenovm vezenovm requested a review from a team December 2, 2024 19:35
Copy link
Contributor

github-actions bot commented Dec 2, 2024

Changes to Brillig bytecode sizes

Generated at commit: 2c1bce9cd8268223ae4d50f81a8265b78e0487e1, compared to commit: 31640e91ba75b9c5200ea66d1f54cc5185e0d196

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
nested_array_dynamic +1 ❌ +0.04%

Full diff report 👇
Program Brillig opcodes (+/-) %
nested_array_dynamic 2,779 (+1) +0.04%

Copy link
Contributor

github-actions bot commented Dec 2, 2024

Peak Memory Sample

Program Peak Memory
keccak256 81.46M
workspace 122.26M
regression_4709 333.68M
ram_blowup_regression 2.55G

Copy link
Contributor

github-actions bot commented Dec 2, 2024

Changes to number of Brillig opcodes executed

Generated at commit: 2c1bce9cd8268223ae4d50f81a8265b78e0487e1, compared to commit: 31640e91ba75b9c5200ea66d1f54cc5185e0d196

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
nested_array_dynamic +1 ❌ +0.03%

Full diff report 👇
Program Brillig opcodes (+/-) %
nested_array_dynamic 3,721 (+1) +0.03%

@jfecher
Copy link
Contributor

jfecher commented Dec 2, 2024

Needing to bring this back is very strange to me. Repeat loads are essentially "trivial loads" and an extra inc rc instruction should just cause our array to be copied rather than mutated.

This is strange to me as well. Of course copying versus mutating can be a breaking change but in the linked issue the two inc_rc instructions should be to the same array in either case. Agreed on needing to investigate further with getting a reproduceable example as well.

I was testing something locally with the array_refcount intrinsic and found an interesting case where the equivalent of

v0 = make_array [FIeld 0]
inc_rc v0
v1 = call array_refcount(v0)
return v1

Was returning 0 somehow. The actual example had another inc_rc after a printout of the first, and the second was zero as well. I wonder if these cases are related to something odd going on with ref counts behind the scenes.

@vezenovm
Copy link
Contributor Author

vezenovm commented Dec 2, 2024

This PR looks to now be causing private_kernel_tail_to_public::tests::enqueued_public_calls_consume_startup_gas to fail...

I'm continuing to investigate.

@vezenovm
Copy link
Contributor Author

vezenovm commented Dec 2, 2024

This PR looks to now be causing private_kernel_tail_to_public::tests::enqueued_public_calls_consume_startup_gas to fail...

@asterite mentioned that reverting #6088 also causes this test to fail...

@jfecher
Copy link
Contributor

jfecher commented Dec 2, 2024

Was returning 0 somehow. The actual example had another inc_rc after a printout of the first, and the second was zero as well. I wonder if these cases are related to something odd going on with ref counts behind the scenes.

Sorry, I forgot the context of what I was looking at. The issue there was that DIE was removing RCs it shouldn't be, specifically the very first one. It's probably not related to this issue after all.

@vezenovm vezenovm mentioned this pull request Dec 3, 2024
5 tasks
@vezenovm
Copy link
Contributor Author

vezenovm commented Dec 3, 2024

This PR looks to now be causing private_kernel_tail_to_public::tests::enqueued_public_calls_consume_startup_gas to fail...

Both tests are passing when this PR is combined with #6585. I've pushed draft of the two merged here #6692

Copy link
Contributor

@jfecher jfecher left a comment

Choose a reason for hiding this comment

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

Sanity check: do we still need this at all after #6585 ?

If so, I'm happy merging this now and creating an issue for later to investigate why the extra load is needed.

@vezenovm
Copy link
Contributor Author

vezenovm commented Dec 3, 2024

Sanity check: do we still need this at all after #6585 ?

If so, I'm happy merging this now and creating an issue for later to investigate why the extra load is needed.

It isn't needed after #6585. We probably can close it, as this PR is a bit of a hack and shouldn't be necessary if we are laying down the correct instructions. It looks to provide an ~10% improvement in the uhashmap execution trace, but with slight increases in bytecode size and execution trace for every other program it affects.

@jfecher
Copy link
Contributor

jfecher commented Dec 3, 2024

It looks to provide an ~10% improvement in the uhashmap execution trace

Ahh, another really odd result. Wish I knew why that was the case too.

Anyway, I'll leave this to you on whether we should merge this or not

@vezenovm
Copy link
Contributor Author

vezenovm commented Dec 5, 2024

I'm going to close this most likely but merging master to see its affect after all the RC changes.

@vezenovm
Copy link
Contributor Author

vezenovm commented Dec 6, 2024

Now we get no improvements from doing this, which is as expected

@vezenovm vezenovm closed this Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-external-checks Trigger CI job to run tests on external repos
Projects
None yet
Development

Successfully merging this pull request may close these issues.

private_kernel_tail_to_public::tests::enqueued_public_calls_with_teardown_gas fails in master
3 participants