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

Breaking: move to JSONStream. remove multibyte option #6

Merged
merged 5 commits into from
Nov 17, 2017

Conversation

DonutEspresso
Copy link
Owner

@DonutEspresso DonutEspresso commented Nov 17, 2017

This moves this module to JSONStream.

The granularity provided by json-stream is nice but was causing parse operations to take much longer than expected. It looks like JSONStream by default using the $* path separates on top level fields, which may be "good enough" for most big JSON cases.

There might be something interesting around customizing the JSONStream path to target parts of the big POJO where known tokens are too large. Could be something for 2.x.

opts.multibyte is also no longer necessary since JSONStream's underlying jsonparse handles it already.

@DonutEspresso DonutEspresso force-pushed the jsonstream branch 3 times, most recently from 2c224e7 to 906a889 Compare November 17, 2017 01:44
@coveralls
Copy link

coveralls commented Nov 17, 2017

Coverage Status

Coverage increased (+3.02%) to 97.959% when pulling a2d3616 on jsonstream into 58aaa92 on master.

Repository owner deleted a comment from coveralls Nov 17, 2017
Repository owner deleted a comment from coveralls Nov 17, 2017
Repository owner deleted a comment from coveralls Nov 17, 2017
Repository owner deleted a comment from coveralls Nov 17, 2017
Repository owner deleted a comment from coveralls Nov 17, 2017
Repository owner deleted a comment from coveralls Nov 17, 2017
Repository owner deleted a comment from coveralls Nov 17, 2017
test/index.js Outdated
@@ -188,79 +189,13 @@ describe('big-json', function() {
parseStream.on('error', function(err) {
assert.ok(err);
assert.equal(err.name, 'Error');
assert.equal(err.message, 'Parser has expected a string value');
assert.equal(err.message, 'Invalid JSON (Unexpected "\\n" ' +

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we couple our tests to the error message? Is having an error with a message enough?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shortened to test just for 'Invalid JSON'. Coupling isn't great, but in this case I do want to verify that it's because of invalid content vs some other internal error.

test/index.js Outdated
return done();
});

readStream.pipe(parseStream);
});


it('should handle multibyte keys and vals', function(done) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we dropping support for multibyte characters?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supported by default now (mentioned in OP :)).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we keep the test to ensure future changes don't break multibyte?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Readded

lib/index.js Outdated
return callback(null, stringified);
}
return null;
return callback(null, stringified);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to wrap the callback in a strict once?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea - added.

@@ -161,24 +180,6 @@ describe('big-json', function() {
});


it('should throw on piping multiple source streams', function(done) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this result in valid behaviour?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In retrospect, technically up to the user - if they want to parse two separate sub objects and merge them into a single object using streams, this would allow them to do so.

This was disallowed before because the impl was done poorly. :)

@coveralls
Copy link

coveralls commented Nov 17, 2017

Coverage Status

Coverage increased (+3.1%) to 98.077% when pulling a1ab36c on jsonstream into 58aaa92 on master.

@coveralls
Copy link

coveralls commented Nov 17, 2017

Coverage Status

Coverage increased (+3.1%) to 98.077% when pulling 6997417 on jsonstream into 58aaa92 on master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+3.1%) to 98.077% when pulling 6997417 on jsonstream into 58aaa92 on master.

@coveralls
Copy link

coveralls commented Nov 17, 2017

Coverage Status

Coverage increased (+3.1%) to 98.077% when pulling 6997417 on jsonstream into 58aaa92 on master.

Copy link

@rajatkumar rajatkumar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, you might want to add a reference to https://github.com/dominictarr/JSONStream in README

@coveralls
Copy link

Coverage Status

Coverage increased (+3.2%) to 98.148% when pulling c51b520 on jsonstream into 58aaa92 on master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+3.2%) to 98.148% when pulling c51b520 on jsonstream into 58aaa92 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+3.2%) to 98.148% when pulling c51b520 on jsonstream into 58aaa92 on master.

@coveralls
Copy link

coveralls commented Nov 17, 2017

Coverage Status

Coverage increased (+3.2%) to 98.148% when pulling 4dcfcf6 on jsonstream into 58aaa92 on master.

return cb();
});
const parseStream = createParseStream(opts);
const sourceStream = intoStream(opts.body);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conversion of in memory string to into readable chunks is going to help a lot - I suspect we were losing I/O here because pushing a giant string into a stream effectively becomes a giant JSON.parse

Copy link

@retrohacker retrohacker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@DonutEspresso DonutEspresso merged commit 43344be into master Nov 17, 2017
@DonutEspresso DonutEspresso deleted the jsonstream branch November 17, 2017 04:29
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.

None yet

4 participants