Skip to content

Pure swap analysis#2606

Draft
girazoki wants to merge 5 commits intoopentensor:devnet-readyfrom
girazoki:girazoki-pure-swap
Draft

Pure swap analysis#2606
girazoki wants to merge 5 commits intoopentensor:devnet-readyfrom
girazoki:girazoki-pure-swap

Conversation

@girazoki
Copy link
Copy Markdown

Description

Substitutes sim_swap for pure_swap, or at least, does an analysis on its benefits and cons. The sim_swap approaches executes a swap and then reverts while pure_swap allows this without reverting back those writes. Initially I thought this writes were actually commited to DB but I realized this is not the case while benchmarking: sim_swap simply maintains in-memory vars that later are discarded.

All in all I think having a pure_swap approach perhaps is more readable and I saw a 38us optimization while benchmarking, probably due to the overhead of having to do with_transaction + rollback in the sim_swap case. But this optimization is negligible if we take into account db reads and writes, which clearly domintate. Additionally, it is also true this pure_swap poses an additional maintainability layer.

At least I want to propose this PR so that the team is aware of my findings. I generated a ton of tests to make sure both yield the same results

Related Issue(s)

  • Closes #[issue number]

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

Breaking Change

If this PR introduces a breaking change, please provide a detailed description of the impact and the migration path for existing applications.

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have run ./scripts/fix_rust.sh to ensure my code is formatted and linted correctly
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Screenshots (if applicable)

Please include any relevant screenshots or GIFs that demonstrate the changes made.

Additional Notes

Please provide any additional information or context that may be helpful for reviewers.

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.

1 participant