pmndrs / valtio

💊 Valtio makes proxy-state simple for React and Vanilla
http://valtio.pmnd.rs
MIT License
8.67k stars 241 forks source link

Fix linear performance degradation in proxy map and proxy set #919

Open kk8787 opened 5 days ago

kk8787 commented 5 days ago

Related Bug Reports or Discussions

Fixes #

Summary

Hello! The company I work for uses Valtio in a product, but when handling CAD files we need to store 1,000 to 50,000 elements, and we are experiencing performance issues with the current implementation., so I fixed it. This is my first time contributing to OSS, so I'm a little nervous. Thank you.

Check List

vercel[bot] commented 5 days ago

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

Name Status Preview Comments Updated (UTC)
valtio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 3, 2024 4:09pm
codesandbox-ci[bot] commented 5 days ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

pkg-pr-new[bot] commented 5 days ago

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

commit: 0c7041a

valtio

``` npm i https://pkg.pr.new/valtio@919 ```


templates

- [default](https://pkg.pr.new/template/69d22192-067b-4beb-8612-afa93b0129b3)

dai-shi commented 5 days ago

This is my first time contributing to OSS, so I'm a little nervous.

That's great!

Unfortunately, this change doesn't work. Proxying Map/Set is very tricky, and what we did is an emulation. So, it's not for performance, but it just provides Map/Set-like APIs.

That said, proxying Map/Set with performance is technically possible under some reasonable constraints, and for example immer does it. It would be very nice if anyone would challenge it. It will provide a performance benefit. We decided not to include it in this repo, but adding such a library in https://github.com/valtiojs is more than welcome.

dai-shi commented 5 days ago

(I will run CI again after #920 is merged.)

kk8787 commented 4 days ago

I see, I might give it a try when I have time. Thank you for your kind reply. I think valtio is the simplest way to integrate VanillaJS libraries with React in a natural way. Thanks for a great library.