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

WIP: replaced diff to diff-match-patch (#3675) #3989

Closed
wants to merge 1 commit into from
Closed

WIP: replaced diff to diff-match-patch (#3675) #3989

wants to merge 1 commit into from

Conversation

jalnanco
Copy link

Description of the Change

I checked the #3675 issue and changed the existing diff library to Google's diff-patch-match.

Benefits

  • Diff speed is improved for large data.

Test Code (copy from issue)

var _ = require('lodash');
const {expect} = require('chai')
it('Test failing', function () {
  const longArray = _.times(10000, function (i) {
    return {a : i}
  })
  const shortArray = []
  expect(longArray).deep.equal(shortArray)
}

Before change: About 2 minutes 1 second

/bin/mocha ../../pycon/mocha/my/test_issue  121.94s user 0.55s system 100% cpu 2:01.74 total

After change: About 1 second

./bin/mocha ../../pycon/mocha/my/test_issue  0.91s user 0.09s system 93% cpu 1.071 total

Applicable issues

Diff-patch-match is character-based, unlike diff.
So it is written to be processed line by line using line-mode.

However, the result screen is different because there is a difference from Patch Process.

Test Code

it('Test failing2', function () {
  const expected = { a: 123 };
  const actual = { a: 123, b: 456 };
  expect(expected).deep.equal(actual);
})

Comparison of Patch Results

Before

Index: string
===================================================================
--- string
+++ string
@@ -1,3 +1,4 @@
 {
   "a": 123
+  "b": 456
 }
\ No newline at end of file

After

@@ -6,9 +6,20 @@
 a": 123

+  "b": 456

 }

Comparison of Excution Results

Before

       {
         "a": 123
      +  "b": 456
       }

After

       a": 123
      +  "b": 456
       }

RESULT

So I don't think it's user friendly.

Would it be better to work on the same output as the existing result? Or would you like to hear other ways to find out?

Please, I want to listen to the comments and advices.

@jsf-clabot
Copy link

jsf-clabot commented Aug 16, 2019

CLA assistant check
All committers have signed the CLA.

@outsideris outsideris added the type: bug a defect, confirmed by a maintainer label Aug 17, 2019
@wnghdcjfe
Copy link
Contributor

I tested it with your code and there was no problem. What part was wrong?

const {expect} = require('chai')
it('Test failing2', function () {
    const expected = { a: 123 };
    const actual = { a: 123, b: 456 };
    expect(expected).deep.equal(actual);
  })
  1) Test failing2:

      AssertionError: expected { a: 123 } to deeply equal { a: 123, b: 456 }
      + expected - actual

       {
         "a": 123
      +  "b": 456
       }

@jalnanco
Copy link
Author

jalnanco commented Sep 11, 2019

I tested it with your code and there was no problem. What part was wrong?

const {expect} = require('chai')
it('Test failing2', function () {
    const expected = { a: 123 };
    const actual = { a: 123, b: 456 };
    expect(expected).deep.equal(actual);
  })
  1) Test failing2:

      AssertionError: expected { a: 123 } to deeply equal { a: 123, b: 456 }
      + expected - actual

       {
         "a": 123
      +  "b": 456
       }

If you use Google's diff-patch-match instead of old diff.
You can get speed but It's difficult to recognize.
Because It's consist of character-based.

So Test is not a problem. Result output is a problem.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants