-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add some magic to arrays manipulation to boost perf #20
Comments
😍 This will give us not only a perf boost, but will also let us cover existing issues and request to support |
BTW, what do I miss something or the only "magic" here is just the Proxies? |
@tomalec there is some actual magic.
Same explanation applies to |
Are you saying that you will overwrite array's native |
Not on the global scope. Only the proxified arrays will be affected. The user will not have to do anything. var myObj = { numbers: [1, 2, 3] };
var jsonPatcherProxy = new JSONPatcherProxy( myObj );
var observedObject = jsonPatcherProxy.observe(true);
observedObject.numbers.shift();
jsonPatcherProxy.generate() // => {op: 'remove', path: '/0'} |
👍 However, then we could miss it in cases like: var myObj = { numbers: [1, 2, 3] };
var jsonPatcherProxy = new JSONPatcherProxy( myObj );
var observedObject = jsonPatcherProxy.observe(true);
Array.prototype.shift.call(observedObject.numbers);
jsonPatcherProxy.generate() // => two replaces and remove |
@tomalec correct, I thought about it but I dug Polymer source and they use |
The good thing is that in the case I describe we will still be JSON Patch compatible, but just less consise. |
Exactly. |
With Starcounter apps this is an edge case, because server only allows It would be 100x more worth it to implement this in C# Palindrom as of now, because that one often generates patches that |
This is in line with what @miyconst said about the same problem here: Palindrom/Palindrom#128 (comment) |
Aha! Didn't know that, even though it's obvious now that I think about it.
I'm not talking looping or any bad design though, |
This brings us to the very old design decision which was and still is:
So, before solving any implementation difficulties, we should reconsider or design decision, and what/why should be allowed, to what extend. |
Consider
When you
arr.shift()
what technically happens isSame happens if you
splice
. But starting from the index you pass. Now imagine you have an array of 1000 items. Shifting it would produce 1000 operations! All sent via web socket. Assuming it's an array of integers (not deep objects), smallest operation is 50 bytes, 50 * 1000 = ~50KB of transfer for deleting a single list item! Can you imagine how slow is this? It takes ~100ms to do a single shift operation on the same host, imagine via network. And this applies tojsonpatch
and to proxies. It's not proxies fault.Proposed solution:
Simply produce a single
remove
operation.How?
With
jsonpatch
this cannot happen. But with proxies when you callshift
andsplice
you're invoking the proxygetter
withkey
=shift
, and I can return to you any method I want. And I can return a specialshift
/splice
function that does exactly the same job for you but emits a single patch instead of N.Challenges
jsonpatch.applyPatch
support: I tested. Applying a remove operation on the array yields the correct results.Objective:
This will give a great boost to general Starcounter performance.
/cc @warpech @tomalec
The text was updated successfully, but these errors were encountered: