Skip to content

Conversation

@spbnick
Copy link
Contributor

@spbnick spbnick commented Sep 15, 2020

In addition to (Unicode) strings, also accept "bytes" (and corresponding iterators) as input to the parser. This allows skipping the decode/encode step when reading raw data from a file or socket, e.g. with os.read(). This introduces small, but measurable performance increase for such cases.

I'm not sure about this one. First about the interface, and then, surprisingly the benefits weren't that great and my (imperfect) testing sometimes showed performance decrease. However, my inner perfectionist says it's a good idea, so I'm posting it, just to get it off my back 😁. Don't hesitate to turn it down if you feel it's not beneficial.

This is based on and requires #49.

@spbnick spbnick changed the title Parser accept bytes as input parser: Accept bytes as input Sep 15, 2020
@spbnick spbnick force-pushed the parser_accept_bytes_as_input branch 3 times, most recently from 622641f to 6490f6f Compare September 15, 2020 13:46
@spbnick spbnick force-pushed the parser_accept_bytes_as_input branch 3 times, most recently from b69f4ce to e41d462 Compare September 21, 2020 13:52
@spbnick
Copy link
Contributor Author

spbnick commented Sep 21, 2020

This has been updated to make jq.parse_json() accept either strings or bytes via the same arguments, instead of separate ones.

@spbnick spbnick force-pushed the parser_accept_bytes_as_input branch from e41d462 to a10ecdd Compare September 21, 2020 14:27
Add an implementation of parse_json() function accepting either text or
a text iterator and producing an iterable returning parsed values.

Add a naive implementation of parse_json_file() function accepting a
text file object and producing an iterable returning parsed values.

This allows parsing JSON and JSON streams without passing them through a
program.
Let Python give us the length of the "bytes" it already knows, instead
of doing an strlen(). This improves performance a bit.
In addition to (Unicode) strings, also accept "bytes" (and corresponding
iterators) as input to the parser. This allows skipping the
decode/encode step when reading raw data from a file or socket, e.g.
with os.read(). This introduces small, but measurable performance
increase for such cases.
@spbnick spbnick force-pushed the parser_accept_bytes_as_input branch from a10ecdd to 11a81a7 Compare February 24, 2021 15:20
@spbnick
Copy link
Contributor Author

spbnick commented May 30, 2024

Closing this outdated PR for another attempt.

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.

1 participant