JSFiddle - React, Tailwind, and code Playground
HTML
<script type="module">
import {immerable, produce, setUseStrictShallowCopy} from "https://unpkg.com/immer@10.0.4-beta/dist/immer.production.mjs"
setUseStrictShallowCopy(false);
class Foo {
[immerable] = true;
a = 1;
b = 2;
c = 3;
d = 4;
e = 5;
f = 6;
g = 7;
h = 8;
i = 9;
j = 10;
k = 11;
l = 12;
}
function test(name, o)
{
const start = performance.now();
console.time(name);
for (let i=0; i<100000; i++) {
produce(o, proxy => {proxy.a = i; });
}
const stop = performance.now();
const elapsed = stop - start;
console.log(name, elapsed);
return elapsed;
}
// test simple class instance
const thing1 = new Foo();
const time1 = test("class", thing1);
// test plain JavaScript with same information
const thing2 = JSON.parse(JSON.stringify(thing1));
const time2 = test("object", thing2);
const ratio = time1/time2;
console.log("x slower with class", ratio);
</script>