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
Array update speed #1117
Comments
Note that Immer also deeply freezes the output, so that is probably a large
portion of your cost here. Might want to play with disabling that, or
freezing arr and the elements inside it first.
…On Wed, Apr 17, 2024 at 10:23 AM pistacchio ***@***.***> wrote:
🐛 Bug Report
I thought that since immer updates arrays directly, it would be more or
less as performant as updating the array directly, but this is not at all
the case.
I simulated the pattern "remove the nth element of an array". Code pasted
later. The results on my machine are:
filter: 186.852ms
immer: 15.871s
splice: 50.453ms
immer seems to be *84 slower* than the standard way to remove the nth
element of an array in a mutable way (which is looping throught all the
elements to remove the given index). This, itself, is not an efficient
method, yet in my example is only ~4 times slower then directly using
Array.splice()
Link to repro
import {produce} from "immer"
const arr = Array.from({length: 10_000_000}, (i, idx) => ({n: idx}));
console.time('filter');let remove10_000nth = arr.filter(((i, idx) => idx !== 10_000));console.timeEnd('filter');
console.time('immer');remove10_000nth = produce(arr, draft => {
draft.splice(10_000, 1)})console.timeEnd('immer');
console.time('splice');arr.splice(10_000, 1);console.timeEnd('splice');
Environment
- *Immer version: 10.0.4*
- I filed this report against the *latest* version of Immer
- Occurs with setUseProxies(true)
- Occurs with setUseProxies(false) (ES5 only)
—
Reply to this email directly, view it on GitHub
<#1117>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4NBDAET3ZSVAKMIFCNEDY5YWRZAVCNFSM6AAAAABGK2G46WVHI2DSMVQWIX3LMV43ASLTON2WKOZSGI2DONRYHAZDEMY>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
🐛 Bug Report
I thought that since immer updates arrays directly, it would be more or less as performant as updating the array directly, but this is not at all the case.
I simulated the pattern "remove the nth element of an array". Code pasted later. The results on my machine are:
immer seems to be 84 slower than the standard way to remove the nth element of an array in a mutable way (which is looping throught all the elements to remove the given index). This, itself, is not an efficient method, yet in my example is only ~4 times slower then directly using
Array.splice()
Link to repro
Environment
setUseProxies(true)
setUseProxies(false)
(ES5 only)The text was updated successfully, but these errors were encountered: