Thanks to visit codestin.com
Credit goes to github.com

Skip to content

perf: improve speed of parsing #16

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

Merged
merged 1 commit into from
Feb 8, 2023
Merged

perf: improve speed of parsing #16

merged 1 commit into from
Feb 8, 2023

Conversation

H4ad
Copy link
Contributor

@H4ad H4ad commented Feb 4, 2023

Hello!

I rewrote the entire function to avoid creating a class during parsing and also calling methods, here are the results of that rewrite:

parseBoolArray('{true}') x 3,600,315 ops/sec ±1.18% (89 runs sampled)
parseBoolArray('{true,false}') x 1,504,719 ops/sec ±1.34% (87 runs sampled)
parseBoolArray('{true,false,true}') x 1,074,796 ops/sec ±1.27% (88 runs sampled)
parseBoolArrayV2('{true}') x 8,257,642 ops/sec ±1.46% (87 runs sampled)
parseBoolArrayV2('{true,false}') x 4,202,999 ops/sec ±1.93% (88 runs sampled)
parseBoolArrayV2('{true,false,true}') x 3,031,024 ops/sec ±1.51% (86 runs sampled)
Fastest is parseBoolArrayV2('{true}')

Benchmark

It improves parsing speed by about 2x to 3x times.

@bendrucker
Copy link
Owner

Nice, thank you!

@bendrucker bendrucker merged commit 1afa554 into bendrucker:master Feb 8, 2023
jimrandomh added a commit to ForumMagnum/ForumMagnum that referenced this pull request Apr 11, 2024
Postgres-array is a dependency of pg-types which is a depndency of pg.
It's responsible for parsing jsonb fields in the results of queries we
run in postgres. This version upgrade causes us to get the changes in
bendrucker/postgres-array#16 , which makes that
particular function ~2-3x faster. I observed that this function was ~2%
of our server CPU time (on a benchmark where I was SSRing a post page
with lots of comments in a loop), and after this upgrade I saw the time
spent in it reduce accordingly.

The version is a major version only because they dropped compatibility
with some old nodejs versions.
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.

2 participants