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

feat(simd): use simd-json for deserialization #216

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

yamafaktory
Copy link
Owner

  • Use simd-json for faster deserialization
  • Use mimalloc instead of the default system allocator for performance

Based on the awesome feedback from @epage here ❤️ !

@yamafaktory yamafaktory self-assigned this Apr 24, 2023
/// Reads a file from `path`.
async fn read_file(path: impl AsRef<Path>) -> Result<String> {
async fn read_file(path: impl AsRef<Path>) -> Result<Vec<u8>> {
let display_path = path.as_ref().display();
let mut file = File::open(&path)

This comment was marked as resolved.

This comment was marked as resolved.

Comment on lines 19 to 21
mimalloc = "0.1.36"
serde_json = { workspace = true }
simd-json = "0.9.0"
Copy link

Choose a reason for hiding this comment

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

Didn't see it mentioned in the PR; how much did this improve performance?

Copy link
Owner Author

Choose a reason for hiding this comment

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

That's the missing piece, not tested yet :)

Copy link
Owner Author

@yamafaktory yamafaktory Apr 25, 2023

Choose a reason for hiding this comment

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

I made a small hyperfine shell script comparing the current binary from main and a release build from this branch.

There's definitely some improvement. Ideally this should be tested against a way bigger JSON file.

Benchmark 1: cat /home/yamafaktory/dev/jql/assets/github-repositories.json | jql '|>{"name","full_name"}' > /dev/null
  Time (mean ± σ):     597.2 ms ±  12.1 ms    [User: 880.7 ms, System: 165.1 ms]
  Range (min … max):   569.9 ms … 629.4 ms    100 runs
 
Benchmark 2: cat /home/yamafaktory/dev/jql/assets/github-repositories.json | /home/yamafaktory/dev/jql/target/release/jql '|>{"name","full_name"}' > /de
v/null
  Time (mean ± σ):     555.8 ms ±  13.9 ms    [User: 1001.4 ms, System: 130.3 ms]
  Range (min … max):   531.7 ms … 648.2 ms    100 runs
 
Summary
  'cat /home/yamafaktory/dev/jql/assets/github-repositories.json | /home/yamafaktory/dev/jql/target/release/jql '|>{"name","full_name"}' > /dev/null' ra
n
    1.07 ± 0.03 times faster than 'cat /home/yamafaktory/dev/jql/assets/github-repositories.json | jql '|>{"name","full_name"}' > /dev/null'

@yamafaktory
Copy link
Owner Author

For the record, this can't be used yet sadly since there's no way to preserve the order of the keys, see simd-lite/simd-json#270.

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

2 participants