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

Implement $read_ndjson() and $scan_ndjson() #471

Merged
merged 8 commits into from
Nov 8, 2023
Merged

Conversation

etiennebacher
Copy link
Collaborator

@etiennebacher etiennebacher commented Nov 6, 2023

TODO:

  • tests
  • bump news
  • maybe refactor common bits with csv functions on the Rust side

@etiennebacher etiennebacher marked this pull request as ready for review November 7, 2023 12:16
@etiennebacher
Copy link
Collaborator Author

The docs failure is due to internal changes in altdoc, I'm taking care of this in #472

@etiennebacher
Copy link
Collaborator Author

Performance looks nice:

ndjson_filename <- tempfile()
df <- head(nycflights13::flights, 200000)
jsonlite::stream_out(df, file(ndjson_filename), verbose = FALSE)

bench::mark(
  ndjson   = ndjson::stream_in(ndjson_filename),
  jsonlite = jsonlite::stream_in(file(ndjson_filename), verbose = FALSE),
  jsonify  = jsonify::from_ndjson(ndjson_filename),
  arrow    = arrow::read_json_arrow(ndjson_filename),
  yyjsonr  = yyjsonr::read_ndjson_file(ndjson_filename),
  polars = polars::pl$read_ndjson(ndjson_filename),
  check = FALSE
)
#> Registered S3 method overwritten by 'jsonify':
#>   method     from    
#>   print.json jsonlite
#> Warning: Some expressions had a GC in every iteration; so filtering is
#> disabled.
#> # A tibble: 6 × 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 ndjson        5.83s    5.83s     0.172   127.8MB    0.515
#> 2 jsonlite      7.31s    7.31s     0.137   278.3MB    0.547
#> 3 jsonify    746.98ms 746.98ms     1.34    105.1MB    1.34 
#> 4 arrow      393.64ms 395.87ms     2.53     27.7MB    0    
#> 5 yyjsonr    356.84ms 364.77ms     2.74     18.4MB    0    
#> 6 polars     119.52ms 126.81ms     7.88      6.9MB    0

R/json.R Outdated Show resolved Hide resolved
@etiennebacher
Copy link
Collaborator Author

etiennebacher commented Nov 8, 2023

Thanks for the review and refactor @sorhawell, I'll do the same thing for CSV reading in another PR

@etiennebacher etiennebacher merged commit cb53e75 into main Nov 8, 2023
22 of 23 checks passed
@etiennebacher etiennebacher deleted the read-json branch November 8, 2023 12:26
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