Skip to content
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

Adding triple equals check to avoid worst case #149

Merged
merged 4 commits into from
Feb 23, 2017

Conversation

KamranAsif
Copy link
Contributor

Currently we walk through the entire subtree of the object. This change allows us to exit early if we see two objects with the same reference at a higher level.

I wasn't able to get the tests to work locally

@tomalec
Copy link
Collaborator

tomalec commented Feb 17, 2017

Thanks for feedback, but I'm not quite sure I get your case. Could you add a test for that?

I wasn't able to get the tests to work locally

At which step it fails? https://github.com/Starcounter-Jack/JSON-Patch/blob/master/CONTRIBUTING.md#testing

@KamranAsif
Copy link
Contributor Author

All tests are failing both in node and in browser, with this error:

OPERATION_PATH_UNRESOLVABLE: Cannot perform the operation at a path that does not exist  OPERATION_PATH_UNRESOLVABLE: Cannot perform the operation at a path that does not exist
      at JsonPatchError.Error (native)
      at new JsonPatchError (JSON-Patch/src/json-patch-duplex.js:493:32)
      at Object.validator (JSON-Patch/src/json-patch-duplex.js:560:27)
      at Object.apply (JSON-Patch/src/json-patch-duplex.js:433:34)
      at Object.validate (JSON-Patch/src/json-patch-duplex.js:587:23)
      at Object.<anonymous> (JSON-Patch/test/spec/validateSpec.js:273:31)
      at attemptSync (JSON-Patch/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1950:24)
      at QueueRunner.run (JSON-Patch/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1938:9)
      at QueueRunner.execute (JSON-Patch/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1923:10)
      at Spec.queueRunnerFactory (JSON-Patch/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:714:35)

I'm not sure how to add a test for this change, since its a performance improvement instead of a normal bug fix. For example:

var largeObj = {....}
compare(largeObj, largeObj); //should be O(1) instead of O(n)

@tomalec
Copy link
Collaborator

tomalec commented Feb 22, 2017

I'm not sure how to add a test for this change, since its a performance improvement instead of a normal bug fix. For example:

var largeObj = {....}
compare(largeObj, largeObj); //should be O(1) instead of O(n)

Thanks, that makes a perfect sense. However we could add another benchmark for it


All tests are failing both in node and in browser, with this error:

That's wierd, I have just cloned a fresh repo,and everything works fine.

git clone https://github.com/Starcounter-Jack/JSON-Patch.git
cd JSON-Patch
npm install
npm test
npm run bench-duplex

Could you provide a full log?
In the meantime I'd try to write a new bench

tomalec added a commit that referenced this pull request Feb 22, 2017
@tomalec tomalec mentioned this pull request Feb 22, 2017
@tomalec
Copy link
Collaborator

tomalec commented Feb 22, 2017

I have added such case 3a020d0 Please tell me, is that what you were talking about?

The difference is huge! So, we will definitely take this. But I'd like to check that there is nothing more to add.

@KamranAsif
Copy link
Contributor Author

KamranAsif commented Feb 22, 2017

@tomalec Looks like the tests are working. Must have been something about my fork.

The benchmarks look good. Might be worth adding a test for large arrays as well.

Out of curiosity, do you have some before & after numbers?

@KamranAsif
Copy link
Contributor Author

KamranAsif commented Feb 22, 2017

Would it be worth moving the check to the top of _generate, so we can capture the case of

var largeIntArray = [....]
compare(largeIntArray, largeIntArray); //This will still run in O(n) time with our change

@tomalec
Copy link
Collaborator

tomalec commented Feb 23, 2017

Would it be worth moving the check to the top of _generate

Would you mind doing that?

@tomalec
Copy link
Collaborator

tomalec commented Feb 23, 2017

Out of curiosity, do you have some before & after numbers?

Here you have numbers before https://travis-ci.org/Starcounter-Jack/JSON-Patch#L637

You can check numbers after by merging with master :)

@tomalec
Copy link
Collaborator

tomalec commented Feb 23, 2017

@KamranAsif please let me know once you are finished with changes, so I'll merge this.

@alshakero
Copy link
Collaborator

Moving to top made it 123% faster! (37402/30403 op/sec) 🎉

@KamranAsif
Copy link
Contributor Author

Done :)

@tomalec tomalec merged commit 5754af9 into Starcounter-Jack:master Feb 23, 2017
@tomalec
Copy link
Collaborator

tomalec commented Feb 23, 2017

But in total this change for object deep for 11 nodes gave us, waaay much better result
37 402 : 60 083 511
Thanks a lot @KamranAsif

@KamranAsif KamranAsif deleted the triple-equals branch February 23, 2017 16:06
@tomalec
Copy link
Collaborator

tomalec commented Feb 23, 2017

Released as 1.1.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants