-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Different performance for computed value written in different ways. #375
Comments
This might very well relate to #360. Another reason that your latter solution might be faster is the fact that you have a local copy of |
I made sandbox https://github.com/kirillsalikhov/flat-finder with un-MobX-ed versions (if I correctly understood you). Results on my computer are: |
Thanks, that is really useful! I'll profile and fix this performance drop. Op wo 29 jun. 2016 om 22:41 schreef kirillsalikhov <notifications@github.com
|
I think this might be related to #250 - accessing the same observable value (in this case, this.filter or filter['Corpus'/'Floor'/'Section']) multiple times within the same derivation. The following change seems to make the non-closure mobx filtering behave the same as the closure one, because it accesses the observables in the same way: this.filter accessed only once, then each filter[name] only accessed if the flat isn't already filtered out. filterFn2 = (filter, flat) => {
var val = true;
if (filter['Corpus']) {
val = val && _.startsWith(flat['Corpus'] + '', filter['Corpus'])
}
if (val && filter['Floor']) {
val = val && _.startsWith(flat['Floor'] + '', filter['Floor'])
}
if (val && filter['Section']) {
val = val && _.startsWith(flat['Section'] + '', filter['Section'])
}
return val;
};
@computed get filtered() {
var filterFn = this[this.filterName];
const filter = this.filter;
return this.flats.filter((flat)=>filterFn(filter, flat));
}``` |
Correct. I experimented a bit with it yesterday, and simply using a hashset Op do 30 jun. 2016 om 20:51 schreef nyura123 notifications@github.com:
|
Did not know about this conference :S. I live next to where it takes place. |
There are 3 tickets left :-) And some tickets are being sold on twitter. Op vr 1 jul. 2016 om 16:00 schreef hellectronic notifications@github.com:
|
Started optimizing for these kind of situations, initial results are very promising :) On the current MobX performance test suite: Before: After: |
@kirillsalikhov the follow build should address this issue and bring the performance back to proportions (with constant instead of exponential overhead). Would you mind verifying that? Thanks! |
Every sample performs almost the same time. |
* Store timing results when running perf tests for easy comparison * First naive set implementation * use real sets -> 10 secs * some notes * Committed perf results with native sets * simple universal set implementation * all tests succeed again * Fixed logging of sort tests * faster bind dependencies * added LRU cache * Better test setup. Perf overhead seems linear now * smarter try finally * optimized use last-accessed-cache * some code simplification * smarter diff * even smarter loops :) * use array for observing, 5% faster, 25% less mem * made sort test trickier * Reserve observing buffer * faster array allocations, ES5 map impl * several fixes and improvements * chores * Fixed some autorun clean up stuff * renames * Fixed a bug in the dependency diffing algorithm
I try to make a simple app which filters json file with ~3000 records. I have slow performance(~2-3s) if I use filter function written with _.reduce and closures inside @computed. And everything works fast if I write it in simpler form(~40ms).
json file looks like:
my model class:
view is simple
If I rewrite get filtered() like below, everything works fine:
I'm not sure if I used @computed the right way
Are there any ways to use complex functions inside @computed ?
The text was updated successfully, but these errors were encountered: