Skip to content

Another benchmark #138

@scriby

Description

@scriby

I've been doing some experimenting with immer. I really like how much simpler it is to write reducers with it!

I was doing some benchmarking vs ImmutableJS and wanted to check if my results make sense.

The benchmark looks like this:

  • Trigger a single action which is handled by one reducer
  • The reducer produces a new state by appending the item's id to the end of an array and adding the item into a map (or plain JS object for immer)

I'm triggering the action 3,000 times, and then measuring the performance of triggering the action another 1,000 times.

The immutable JS reducer takes about 400ms, and the immer reducer takes about 4 seconds. Here's the immer profile:

image

It looks like the main cost is incurred by producing copies of the state as the state is supposed to be immutable, which has to happen for each triggered action. And that's also the main part that ImmutableJS is able to optimize away.

I just wanted to check with you on whether that basically made sense and whether you had any thoughts on it. (When running immer, proxies are used and freezing is off. Browser is Chrome.)

Thanks,

Chris

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions