NewsCrawler.org

Command-line JSON filtering at 20 GB/s with sjq

Command-line JSON filtering at 20 GB/s with sjq
1 GB of NDJSON
One 840 MB document
Image: Reddit

Daniel Lemire built sjq, a command-line tool that reads the language of jq[1], a tool for filtering JSON. On a 1 GB file of tweets stored as NDJSON[2], extracting one field took jq 1.8.2 11.5 seconds, less than 0.1 GB/s. sjq runs on the simdjson[3] parser, and with one thread it took 0.31 seconds, or 3.5 GB/s, about 37 times faster than jq.

With the -P option, sjq uses up to 32 threads and finished the same filter in 0.05 seconds, or 20 GB/s, about 210 times faster than jq on a 64-core server. The author gives three reasons: parsing is most of the work, simdjson parses only what a filter needs to navigate and select, and log files are many small documents that sjq splits across workers. A single large document runs on one core and is still 12 to 18 times faster than jq.

sjq passes 728 of the 781 tests in jq's own test suite, and the failures mostly concern modules, numbers wider than 64 bits, values nested more than 10,000 levels deep, and some error messages. There are other differences, such as regular expressions that use the C++ standard library syntax and dates in UTC. The --fractured option prints output in the FracturedJson[4] layout, which keeps short arrays and objects on one line and aligns arrays of similar records into tables. sjq installs on Linux, macOS and Windows with a script, Homebrew or Scoop, and the author says it is new and asks for reports of wrong results.

Repository sjq github.com

Command-line tool that filters JSON in the style of jq, built on the simdjson parser, running much faster on large files.

Stars: 4Forks: 0License: Apache-2.0Updated:

Read the original lemire.meDiscussion

Sources

Published: First seen: Читать по-русски

Open as a page