เอ็นจิ้น JSONPath รุ่นทดลองสำหรับการสืบค้นชุดข้อมูลที่มีการสตรีมจำนวนมาก
ลัง rsonpath
จัดเตรียมตัวแยกวิเคราะห์ JSONPath และกลไกการดำเนินการสืบค้น rq
ซึ่งใช้คำสั่ง SIMD เพื่อปรับปรุงปริมาณงานอย่างมากเหนือกลไกทั่วไป
เกณฑ์มาตรฐานของ rsonpath
เทียบกับกลไกอ้างอิง no-SIMD บนชุดข้อมูล Pison หมายเหตุ: สเกลเป็นลอการิทึม!
หากต้องการเรียกใช้แบบสอบถาม JSONPath บนไฟล์ให้ดำเนินการ:
rq '$..a.b' ./file.json
หากละเว้นไฟล์ กลไกจะอ่านอินพุตมาตรฐาน JSON สามารถส่งผ่านอินไลน์ได้:
$ rq ' $..a.b ' --json ' {"c":{"a":{"b":42}}} '
42
สำหรับรายละเอียด โปรดปรึกษา rq --help
หรือ rsonbook
ผลลัพธ์ของการเรียกใช้แบบสอบถามคือลำดับของค่าที่ตรงกัน โดยคั่นด้วยการขึ้นบรรทัดใหม่ อีกทางหนึ่ง การส่ง --result count
จะส่งคืนเฉพาะจำนวนการแข่งขัน ซึ่งอาจเร็วกว่ามาก สำหรับโหมดผลลัพธ์อื่นๆ โปรดดูหน้า --help
การใช้งาน
ดูการเผยแพร่สำหรับไบนารีที่คอมไพล์แล้วสำหรับเป้าหมายการสนับสนุนชั้นหนึ่งทั้งหมด
cargo
วิธีที่ง่ายที่สุดในการติดตั้งคือผ่านทาง cargo
$ cargo install rsonpath
...
หากความเร็วสูงสุดเป็นสิ่งสำคัญยิ่ง คุณควรติดตั้ง rsonpath
พร้อมการสนับสนุนคำสั่ง CPU แบบเนทีฟ ซึ่งจะส่งผลให้ไบนารี่ ไม่ สามารถพกพาได้และอาจทำงานไม่ถูกต้องบนเครื่องอื่น แต่จะบีบปริมาณงานบิตสุดท้ายออกไป
เมื่อต้องการทำเช่นนี้ เรียกใช้ชุดตัวเลือก cargo install
ต่อไปนี้:
$ RUSTFLAGS= " -C target-cpu=native " cargo install rsonpath
...
ตรวจสอบบทที่เกี่ยวข้องใน rsonbook
โปรเจ็กต์ได้รับการพัฒนาอย่างแข็งขันและปัจจุบันรองรับเพียงชุดย่อยของภาษาคิวรี JSONPath แบบสอบถามคือลำดับของเซ็กเมนต์ โดยแต่ละเซ็กเมนต์ประกอบด้วยตัวเลือกตั้งแต่ 1 ตัวขึ้นไป
เซ็กเมนต์ | ไวยากรณ์ | รองรับ | เนื่องจาก | ปัญหาการติดตาม |
---|---|---|---|---|
ส่วนย่อย (เดี่ยว) | [<selector>] | เวอร์ชัน 0.1.0 | ||
ส่วนย่อย (หลายรายการ) | [<selector1>,...,<selectorN>] | |||
ส่วนสืบทอด (เดี่ยว) | ..[<selector>] | เวอร์ชัน 0.1.0 | ||
ส่วนสืบทอด (หลายรายการ) | ..[<selector1>,...,<selectorN>] |
ตัวเลือก | ไวยากรณ์ | รองรับ | เนื่องจาก | ปัญหาการติดตาม |
---|---|---|---|---|
ราก | $ | เวอร์ชัน 0.1.0 | ||
ชื่อ | .<member> , [<member>] | เวอร์ชัน 0.1.0 | ||
ไวลด์การ์ด | .* , ..* , [*] | เวอร์ชัน 0.4.0 | ||
ดัชนี (ดัชนีอาร์เรย์) | [<index>] | เวอร์ชัน 0.5.0 | ||
ดัชนี (ดัชนีอาร์เรย์จากจุดสิ้นสุด) | [-<index>] | |||
การแบ่งอาร์เรย์ (ไปข้างหน้า ขอบเขตบวก) | [<start>:<end>:<step>] | เวอร์ชัน 0.9.0 | #152 | |
การแบ่งอาร์เรย์ (ไปข้างหน้า ขอบเขตโดยพลการ) | [<start>:<end>:<step>] | |||
การแบ่งอาร์เรย์ (ย้อนกลับ ขอบเขตโดยพลการ) | [<start>:<end>:-<step>] | |||
ตัวกรอง – การทดสอบที่มีอยู่ | [?<path>] | #154 | ||
ตัวกรอง – การเปรียบเทียบอะตอมแบบ const | [?<path> <binop> <atom>] | #156 | ||
ตัวกรอง – นิพจน์เชิงตรรกะ | && , || , ! | |||
ตัวกรอง – การซ้อน | [?<expr>[?<expr>]...] | |||
ตัวกรอง – การเปรียบเทียบโดยพลการ | [?<path> <binop> <path>] | |||
ตัวกรอง – ส่วนขยายฟังก์ชัน | [?func(<path>)] |
ลังถูกสร้างขึ้นอย่างต่อเนื่องสำหรับเป้าหมาย Tier 1 Rust ทั้งหมด และการทดสอบจะดำเนินการอย่างต่อเนื่องสำหรับเป้าหมายที่สามารถวิ่งด้วยอิมเมจการกระทำของ GitHub SIMD รองรับบนแพลตฟอร์ม x86/x86_64 เท่านั้น
เป้าหมายสามเท่า | การสร้าง nosimd | รองรับซิม | การทดสอบอย่างต่อเนื่อง | ปัญหาการติดตาม |
---|---|---|---|---|
aarch64-unknown-linux-gnu.php? | #21, #115 | |||
i686-ไม่ทราบ-linux-gnu | ||||
x86_64-ไม่ทราบ-linux-gnu | ||||
x86_64-แอปเปิ้ลดาร์วิน | ||||
i686-pc-windows-gnu | ||||
i686-pc-windows-msvc | ||||
x86_64-pc-windows-gnu | ||||
x86_64-pc-windows-msvc |
การสนับสนุน SIMD ถูกเปิดใช้งานในแต่ละโมดูล โดยทั่วไป CPU ใดๆ ที่เปิดตัวในทศวรรษที่ผ่านมาจะรองรับ AVX2 ซึ่งช่วยให้สามารถเพิ่มประสิทธิภาพที่มีอยู่ทั้งหมดได้
CPU รุ่นเก่าที่มี SSE2 หรือสูงกว่าจะได้รับการรองรับบางส่วน คุณสามารถตรวจสอบสิ่งที่เปิดใช้งานได้ด้วย rq --version
- ตรวจสอบช่อง SIMD support
:
$ rq --version
rq 0.9.1
Commit SHA: c024e1bab89610455537b77aed249d2a05a81ed6
Features: default,simd
Opt level: 3
Target triple: x86_64-unknown-linux-gnu
Codegen flags: link-arg=-fuse-ld=lld
SIMD support: avx2;fast_quotes;fast_popcnt
ความสามารถ fast_quotes
ขึ้นอยู่กับคำสั่ง pclmulqdq
และ fast_popcnt
บนคำสั่ง popcnt
ตัวเลือกบางตัวไม่ได้รับการสนับสนุน โปรดดูตารางการสนับสนุนด้านบน
กลไกจะถือว่าทุกออบเจ็กต์ในอินพุต JSON ไม่มีคีย์ที่ซ้ำกัน การทำงานของคีย์ที่ซ้ำกันไม่รับประกันว่าจะเสถียร แต่ในปัจจุบันกลไกจะจับคู่คีย์ดังกล่าว ตัวแรก เท่านั้น
$ rq ' $.key ' --json ' {"key":"value","key":"other value"} '
"value"
โปรแกรม ไม่ แยกวิเคราะห์ลำดับหลีกยูนิโค้ดในชื่อสมาชิก ซึ่งหมายความว่าคีย์ "a"
แตกต่างจากคีย์ "u0041"
แม้ว่าจะเป็นตัวแทนสตริงเดียวกันก็ตาม นี่เป็นจริงตามที่ออกแบบโดยคำนึงถึงข้อกำหนด JSONPath ปัจจุบัน การแยกวิเคราะห์ลำดับยูนิโค้ดมีค่าใช้จ่ายสูง ดังนั้นการสนับสนุนนี้จึงถูกเลื่อนออกไปเพื่อให้มีประสิทธิภาพสูง ติดตามได้ที่ #117
สิ่งสำคัญคือ แยก นำไปใช้ ประชาสัมพันธ์กลับมาที่นี่ รายละเอียดเพิ่มเติมอยู่ในเอกสารการมีส่วนร่วม
เวิร์กโฟลว์ dev ใช้ just
. ใช้ Justfile
ที่ให้มาด้วย มันจะติดตั้ง Rust ให้คุณโดยอัตโนมัติโดยใช้เครื่องมือ rustup
หากตรวจพบว่าไม่มีสินค้าในสภาพแวดล้อมของคุณ
$ just build
...
$ just test
...
เกณฑ์มาตรฐานสำหรับ rsonpath
อยู่ในที่เก็บแยกต่างหาก ซึ่งรวมเป็นโมดูลย่อย git ในที่เก็บหลักนี้
วิธีที่ง่ายที่สุดในการรันการวัดประสิทธิภาพทั้งหมดคือ just bench
สำหรับรายละเอียด โปรดดูที่ README ในโมดูลย่อย
เรามีบทความเกี่ยวกับ rsonpath
ที่จะเผยแพร่ที่ ASPLOS '24! คุณสามารถอ่านได้ที่นี่
โครงการนี้ถือเป็นวิทยานิพนธ์ของฉัน คุณสามารถอ่านรายละเอียดเกี่ยวกับภูมิหลังทางทฤษฎีของเครื่องยนต์และรายละเอียดการใช้งานได้
แสดงการขึ้นต่อกันโดยตรง สำหรับกราฟแบบเต็ม ดูด้านล่าง
cargo tree --package rsonpath --edges normal --depth 1
rsonpath v0.9.1 (/home/mat/src/rsonpath/crates/rsonpath)
├── clap v4.5.4
├── color-eyre v0.6.3
├── eyre v0.6.12
├── log v0.4.21
├── rsonpath-lib v0.9.1 (/home/mat/src/rsonpath/crates/rsonpath-lib)
├── rsonpath-syntax v0.3.1 (/home/mat/src/rsonpath/crates/rsonpath-syntax)
└── simple_logger v4.3.3
[build-dependencies]
├── rustflags v0.1.5
└── vergen v8.3.1
[build-dependencies]
cargo tree --package rsonpath-lib --edges normal --depth 1
rsonpath-lib v0.9.1 (/home/mat/src/rsonpath/crates/rsonpath-lib)
├── arbitrary v1.3.2
├── cfg-if v1.0.0
├── log v0.4.21
├── memmap2 v0.9.4
├── nom v7.1.3
├── rsonpath-syntax v0.3.1 (/home/mat/src/rsonpath/crates/rsonpath-syntax)
├── smallvec v1.13.2
├── static_assertions v1.1.0
├── thiserror v1.0.58
└── vector-map v1.0.1
clap
– ลังมาตรฐานสำหรับ CLIcolor-eyre
, eyre
- ข้อความแสดงข้อผิดพลาดที่เข้าถึงได้มากขึ้นสำหรับ parserlog
, simple-logger
– บันทึกการวินิจฉัยระหว่างการคอมไพล์และการดำเนินการcfg-if
– ใช้เพื่อรองรับเวอร์ชัน SIMD และ no-SIMDmemmap2
– สำหรับการอ่านไฟล์ต้นฉบับอย่างรวดเร็วผ่านการแมปหน่วยความจำ แทนสำเนาที่บัฟเฟอร์nom
– สำหรับการดำเนินการแยกวิเคราะห์smallvec
– สำคัญสำหรับประสิทธิภาพของสแต็กขนาดเล็กstatic_assertions
- ความน่าเชื่อถือเพิ่มเติมโดยสมมติฐานคงที่ที่ได้รับการตรวจสอบ ณ เวลารวบรวมthiserror
– การใช้งาน Error
ที่เป็นสำนวนvector_map
– ใช้ในคอมไพเลอร์แบบสอบถามเพื่อประสิทธิภาพที่ดีขึ้นที่วัดได้ cargo tree --package rsonpath --edges normal
rsonpath v0.9.1 (/home/mat/src/rsonpath/crates/rsonpath)
├── clap v4.5.4
│ ├── clap_builder v4.5.2
│ │ ├── anstream v0.6.13
│ │ │ ├── anstyle v1.0.6
│ │ │ ├── anstyle-parse v0.2.3
│ │ │ │ └── utf8parse v0.2.1
│ │ │ ├── anstyle-query v1.0.2
│ │ │ │ └── windows-sys v0.52.0
│ │ │ │ └── windows-targets v0.52.4
│ │ │ │ ├── windows_aarch64_gnullvm v0.52.4
│ │ │ │ ├── windows_aarch64_msvc v0.52.4
│ │ │ │ ├── windows_i686_gnu v0.52.4
│ │ │ │ ├── windows_i686_msvc v0.52.4
│ │ │ │ ├── windows_x86_64_gnu v0.52.4
│ │ │ │ ├── windows_x86_64_gnullvm v0.52.4
│ │ │ │ └── windows_x86_64_msvc v0.52.4
│ │ │ ├── anstyle-wincon v3.0.2
│ │ │ │ ├── anstyle v1.0.6
│ │ │ │ └── windows-sys v0.52.0 (*)
│ │ │ ├── colorchoice v1.0.0
│ │ │ └── utf8parse v0.2.1
│ │ ├── anstyle v1.0.6
│ │ ├── clap_lex v0.7.0
│ │ ├── strsim v0.11.1
│ │ └── terminal_size v0.3.0
│ │ ├── rustix v0.38.32
│ │ │ ├── bitflags v2.5.0
│ │ │ ├── errno v0.3.8
│ │ │ │ ├── libc v0.2.153
│ │ │ │ └── windows-sys v0.52.0 (*)
│ │ │ ├── libc v0.2.153
│ │ │ ├── linux-raw-sys v0.4.13
│ │ │ └── windows-sys v0.52.0 (*)
│ │ └── windows-sys v0.48.0
│ │ └── windows-targets v0.48.5
│ │ ├── windows_aarch64_gnullvm v0.48.5
│ │ ├── windows_aarch64_msvc v0.48.5
│ │ ├── windows_i686_gnu v0.48.5
│ │ ├── windows_i686_msvc v0.48.5
│ │ ├── windows_x86_64_gnu v0.48.5
│ │ ├── windows_x86_64_gnullvm v0.48.5
│ │ └── windows_x86_64_msvc v0.48.5
│ └── clap_derive v4.5.4 (proc-macro)
│ ├── heck v0.5.0
│ ├── proc-macro2 v1.0.79
│ │ └── unicode-ident v1.0.12
│ ├── quote v1.0.35
│ │ └── proc-macro2 v1.0.79 (*)
│ └── syn v2.0.58
│ ├── proc-macro2 v1.0.79 (*)
│ ├── quote v1.0.35 (*)
│ └── unicode-ident v1.0.12
├── color-eyre v0.6.3
│ ├── backtrace v0.3.71
│ │ ├── addr2line v0.21.0
│ │ │ └── gimli v0.28.1
│ │ ├── cfg-if v1.0.0
│ │ ├── libc v0.2.153
│ │ ├── miniz_oxide v0.7.2
│ │ │ └── adler v1.0.2
│ │ ├── object v0.32.2
│ │ │ └── memchr v2.7.2
│ │ └── rustc-demangle v0.1.23
│ │ [build-dependencies]
│ │ └── cc v1.0.90
│ ├── eyre v0.6.12
│ │ ├── indenter v0.3.3
│ │ └── once_cell v1.19.0
│ ├── indenter v0.3.3
│ ├── once_cell v1.19.0
│ └── owo-colors v3.5.0
├── eyre v0.6.12 (*)
├── log v0.4.21
├── rsonpath-lib v0.9.1 (/home/mat/src/rsonpath/crates/rsonpath-lib)
│ ├── cfg-if v1.0.0
│ ├── log v0.4.21
│ ├── memmap2 v0.9.4
│ │ └── libc v0.2.153
│ ├── nom v7.1.3
│ │ ├── memchr v2.7.2
│ │ └── minimal-lexical v0.2.1
│ ├── rsonpath-syntax v0.3.1 (/home/mat/src/rsonpath/crates/rsonpath-syntax)
│ │ ├── nom v7.1.3 (*)
│ │ ├── owo-colors v4.0.0
│ │ ├── thiserror v1.0.58
│ │ │ └── thiserror-impl v1.0.58 (proc-macro)
│ │ │ ├── proc-macro2 v1.0.79 (*)
│ │ │ ├── quote v1.0.35 (*)
│ │ │ └── syn v2.0.58 (*)
│ │ └── unicode-width v0.1.11
│ ├── smallvec v1.13.2
│ ├── static_assertions v1.1.0
│ ├── thiserror v1.0.58 (*)
│ └── vector-map v1.0.1
│ ├── contracts v0.4.0 (proc-macro)
│ │ ├── proc-macro2 v1.0.79 (*)
│ │ ├── quote v1.0.35 (*)
│ │ └── syn v1.0.109
│ │ ├── proc-macro2 v1.0.79 (*)
│ │ ├── quote v1.0.35 (*)
│ │ └── unicode-ident v1.0.12
│ └── rand v0.7.3
│ ├── getrandom v0.1.16
│ │ ├── cfg-if v1.0.0
│ │ ├── libc v0.2.153
│ │ └── wasi v0.9.0+wasi-snapshot-preview1
│ ├── libc v0.2.153
│ ├── rand_chacha v0.2.2
│ │ ├── ppv-lite86 v0.2.17
│ │ └── rand_core v0.5.1
│ │ └── getrandom v0.1.16 (*)
│ ├── rand_core v0.5.1 (*)
│ └── rand_hc v0.2.0
│ └── rand_core v0.5.1 (*)
├── rsonpath-syntax v0.3.1 (/home/mat/src/rsonpath/crates/rsonpath-syntax) (*)
└── simple_logger v4.3.3
├── colored v2.1.0
│ ├── lazy_static v1.4.0
│ └── windows-sys v0.48.0 (*)
├── log v0.4.21
├── time v0.3.34
│ ├── deranged v0.3.11
│ │ └── powerfmt v0.2.0
│ ├── itoa v1.0.11
│ ├── libc v0.2.153
│ ├── num-conv v0.1.0
│ ├── num_threads v0.1.7
│ │ └── libc v0.2.153
│ ├── powerfmt v0.2.0
│ ├── time-core v0.1.2
│ └── time-macros v0.2.17 (proc-macro)
│ ├── num-conv v0.1.0
│ └── time-core v0.1.2
└── windows-sys v0.48.0 (*)
[build-dependencies]
├── rustflags v0.1.5
└── vergen v8.3.1
├── anyhow v1.0.81
├── cargo_metadata v0.18.1
│ ├── camino v1.1.6
│ │ └── serde v1.0.197
│ │ └── serde_derive v1.0.197 (proc-macro)
│ │ ├── proc-macro2 v1.0.79 (*)
│ │ ├── quote v1.0.35 (*)
│ │ └── syn v2.0.58 (*)
│ ├── cargo-platform v0.1.8
│ │ └── serde v1.0.197 (*)
│ ├── semver v1.0.22
│ │ └── serde v1.0.197 (*)
│ ├── serde v1.0.197 (*)
│ ├── serde_json v1.0.115
│ │ ├── itoa v1.0.11
│ │ ├── ryu v1.0.17
│ │ └── serde v1.0.197 (*)
│ └── thiserror v1.0.58 (*)
├── cfg-if v1.0.0
├── regex v1.10.4
│ ├── aho-corasick v1.1.3
│ │ └── memchr v2.7.2
│ ├── memchr v2.7.2
│ ├── regex-automata v0.4.6
│ │ ├── aho-corasick v1.1.3 (*)
│ │ ├── memchr v2.7.2
│ │ └── regex-syntax v0.8.3
│ └── regex-syntax v0.8.3
├── rustc_version v0.4.0
│ └── semver v1.0.22 (*)
└── time v0.3.34
├── deranged v0.3.11 (*)
├── itoa v1.0.11
├── libc v0.2.153
├── num-conv v0.1.0
├── num_threads v0.1.7 (*)
├── powerfmt v0.2.0
└── time-core v0.1.2
[build-dependencies]
└── rustversion v1.0.14 (proc-macro)