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

performance and other stuff from https://github.com/schteppe/p2.js/pull/366 recreated #118

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

Conversation

amytimed
Copy link

basically, i saw schteppe#366, and then i saw this, and then i thought "wouldnt it be really cool to have both in one, typescript maintained version + the perf benefits?" and then i did that

passes all tests

@vercel
Copy link

vercel bot commented Oct 12, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
p2-es ❌ Failed (Inspect) Oct 12, 2023 1:32am

@isaac-mason
Copy link
Member

isaac-mason commented Oct 30, 2023

Thanks for the PR! I will review this soon 🙂

@isaac-mason
Copy link
Member

isaac-mason commented Nov 8, 2023

Thanks again for the PR!

This PR has a bit in it, so I've separated out the change for deferring addition and removal of objects while stepping into a separate commit, this is a WIP on the next branch, see: eabee3f
(I've made sure to credit you in the changeset! 🙂)

I made a few changes too:

  • Deferred changes are handled after every internal step
  • Deferred changes are replayed in order (e.g. if you added a body, removed it, then added it back, this would behave as expected)
  • Modified the existing duringStep tests to assert that changes are correctly deferred
  • Updated JSDoc explaining the behaviour difference when adding/removing while stepping

Also, I've created an issue to track this and other potential improvements: #130

I'll look to get this into master and released soon!


Regarding the other performance changes caching length, it would be good to do some benchmarking to understand what the change in performance is before merging. I'm happy to help with this 🙂


As for what we should do with this PR, we can either close it and create a new PR based on next just adding the performance changes, or we can repurpose this one and do the same.

If you have time to do either of the above, feel free to, otherwise I can in the coming weeks!


LMK if you have any questions, and thanks again

@amytimed
Copy link
Author

amytimed commented Nov 8, 2023

Regarding the other performance changes caching length, it would be good to do some benchmarking to understand what the change in performance is before merging.

it would definitely be helpful to do some benchmarking for that, but in general even if it isn't that much faster, it would be better practice to cache length instead of getting it every time

theres also other performance changes like using for instead of indexOf, which the original PR author claims increased performance, and which seems to be backed up by some articles I found: https://medium.com/@mrashes2/indexof-vs-for-loop-6a9f7bd5c646 though I have not tested this myself

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.

2 participants