I read from various sources that mobx is superior to the renderer response and faster than shrinking. However, if I did a couple of tests, this shows that adding new data to the observed mobx is rather slow. In environments with a reaction-environment, every millisecond is calculated, and itβs difficult to use a solution where even a cycle of more than 200 elements and a filling array takes more than 100 ms. Since I really like mobx, I hope someone can take a look at the test code and give me some Tips - what I am doing wrong and how to improve productivity.
import {observable, transaction,autorun} from 'mobx';
class Runner {
list = observable([]);
run() {
const start = new Date().getTime();
transaction(() => {
for (let i = 0; i < 200; i++) {
this.list.push({
id: observable(i),
one: observable('1'),
two: '2',
three: 3,
x: 'xxxxx',
y: 'yyyyy',
z: 'zzzzz',
z1: 'zzzzz',
z2: 'zzzzz',
z3: 'zzzzz',
z4: 'zzzzz',
});
}
});
console.log('Execution time: ' + (new Date().getTime() - start) + 'ms services ');
}
}
const runner = new Runner();
autorun(() => console.log(runner.list));
runner.run();
It takes about 120 ms on my laptop. Without observables, s takes less than 1 ms
source
share