Skip to content

Commit 62d336f

Browse files
authored
Merge pull request #618 from rsonquery/v0ldek/#613-non-borrowed-string-pattern
Added StringPattern and made Automaton no longer borrow the query
2 parents f040b2a + 237d563 commit 62d336f

32 files changed

+420
-390
lines changed

Justfile

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ default: (build-all "release")
66
# === INIT ===
77

88
# Initialize the repository for development.
9-
init: check-cargo hooks-init checkout-benchmarks
9+
init: check-cargo hooks-init checkout-submodules
1010

1111
# Check if cargo is installed and install it from rustup if not.
1212
[private]
@@ -28,10 +28,15 @@ init: check-cargo hooks-init checkout-benchmarks
2828

2929
# Checkout and populate the benchmarks repository, excluding datasets.
3030
[private]
31-
checkout-benchmarks:
31+
@checkout-submodules:
3232
git submodule init
3333
git submodule update
3434

35+
# Initialize the benchmarks crate.
36+
[private]
37+
@init-benchmarks:
38+
cd crates/rsonpath-benchmarks && just init
39+
3540
# === BUILD ===
3641

3742
alias b := build-bin
@@ -247,7 +252,7 @@ hook-pre-commit:
247252
(just verify-fmt && just verify-check);
248253

249254
[private]
250-
@hook-post-checkout: checkout-benchmarks
255+
@hook-post-checkout: checkout-submodules
251256

252257
[private]
253258
assert-benchmarks-committed:

crates/rsonpath-benchmarks/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ libc = "0.2.168"
3333
lazy_static = "1.5.0"
3434
serde_json = "1.0.134"
3535
sha2 = "0.10.8"
36-
ouroboros = "0.18.4"
3736
reqwest = { version = "0.12.9", features = ["blocking"] }
3837
rsonpath-lib = { version = "0.9.1", default-features = false }
3938
rsonpath-syntax = { version = "0.3.1", default-features = false }

crates/rsonpath-benchmarks/Justfile

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
[private]
22
default: build-bench
33

4+
init:
5+
cd ./src/implementations/jsurferShim && gradle wrapper
6+
47
# === BUILD ===
58

69
alias b := build-bench

crates/rsonpath-benchmarks/README.md

+7-52
Original file line numberDiff line numberDiff line change
@@ -12,60 +12,21 @@ Benchmark suite for [`rsonpath`](https://github.com/v0ldek/rsonpath).
1212

1313
## Prerequisites
1414

15-
By default, the benches are performed against a released version of `rsonpath`.
16-
Usually you might want to run it against the local version to test your changes.
17-
To do that, pass a [patch config value] to `cargo`:
15+
By default, the benches are performed against the local version of `rsonpath` in the local repository.
1816

19-
```ini
20-
--config 'patch.crates-io.rsonpath.path = "../rsonpath"'
21-
```
22-
23-
Additionally:
24-
25-
1. An appropriate C++ compiler is required for the [`cc` crate](https://lib.rs/crates/cc) to compile the
26-
JSONSki code.
27-
2. JDK of version at least 8 is required and your `JAVA_HOME` environment variable must be set
17+
1. JDK of version at least 8 is required and your `JAVA_HOME` environment variable must be set
2818
to its location.
19+
2. You need `gradle` to create the required wrapper JAR to build JSurfer. To install `gradle` it's recommended to use
20+
[`SDKMan`](https://sdkman.io/): `sdk install gradle 7.5`. After that is done, run `just init` in the root of `rsonpath-benchmarks`.
21+
This needs to be done only once.
2922

3023
On x86_64 Ubuntu the latters can be done by installing `openjdk-17-jdk` and exporting `JAVA_HOME` as
3124
`/usr/lib/jvm/java-1.17.0-openjdk-amd64`.
3225

3326
### Download the dataset
3427

35-
On a UNIX system with `wget` installed run the script `sh dl.sh`.
36-
You can also manually download the dataset and put the JSON files in the correct folder.
37-
38-
For more information, refers to:
39-
40-
* AST: [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7229269.svg)](https://doi.org/10.5281/zenodo.7229269)
41-
* Twitter: [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7229287.svg)](https://doi.org/10.5281/zenodo.7229287)
42-
* Crossref: [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7229287.svg)](https://doi.org/10.5281/zenodo.7231920)
43-
44-
For the benchmark to work, the directory layout should be as follows:
45-
46-
```ini
47-
── data
48-
   ├── ast
49-
   │   └── ast.json
50-
   ├── crossref
51-
   │   ├── crossref0.json
52-
   │   ├── crossref16.json
53-
   │   ├── crossref1.json
54-
   │   ├── crossref2.json
55-
   │   ├── crossref4.json
56-
   │   └── crossref8.json
57-
   └── twitter
58-
   └── twitter.json
59-
```
60-
61-
The sha256sum of the JSON files, for reference:
62-
63-
* `c3ff840d153953ee08c1d9622b20f8c1dc367ae2abcb9c85d44100c6209571af ast/ast.json`
64-
* `f76da4fbd5c18889012ab9bbc222cc439b4b28f458193d297666f56fc69ec500 crossref/crossref/crossref1.json`
65-
* `95e0038e46ce2e94a0f9dde35ec7975280194220878f83436e320881ccd252b4 crossref/crossref/crossref2.json`
66-
* `f14e65d4f8df3c9144748191c1e9d46a030067af86d0cc03cc67f22149143c5d twitter/twitter.json`
67-
68-
TODO: checksums of other crossrefs
28+
Datasets are automatically downloaded on demand when an appropriate benchmark is ran. The datasets are also
29+
automatically checked against their known SHA256 checksum to verify integrity.
6930

7031
## Usage
7132

@@ -83,12 +44,6 @@ cargo bench --bench <dataset> --no-default-features
8344

8445
The folder `target/criterion` contains all the information needed to plot the experiment.
8546

86-
As a reminder, to test against local changes instead of a crates.io version:
87-
88-
```bash
89-
cargo bench --bench <dataset> --config 'patch.crates-io.rsonpath.path = "../rsonpath"'
90-
```
91-
9247
## Plotting
9348

9449
To plot the result once the is bench done:

crates/rsonpath-benchmarks/src/implementations/rsonpath.rs

+18-51
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
use crate::framework::implementation::Implementation;
2-
use ouroboros::self_referencing;
2+
use rsonpath::{engine::Compiler, input::MmapInput};
33
use rsonpath::{
4-
engine::main::MainEngine,
4+
engine::{main::MainEngine, Engine},
55
input::OwnedBytes,
66
result::{Match, Sink},
77
};
8-
use rsonpath::{
9-
engine::{Compiler, Engine},
10-
input::MmapInput,
11-
};
12-
use rsonpath_syntax::JsonPathQuery;
138
use std::{convert::Infallible, fmt::Display, fs, io};
149
use thiserror::Error;
1510

@@ -18,16 +13,8 @@ pub struct RsonpathCount {}
1813
pub struct RsonpathMmap {}
1914
pub struct RsonpathMmapCount {}
2015

21-
#[self_referencing()]
22-
pub struct RsonpathQuery {
23-
query: JsonPathQuery,
24-
#[borrows(query)]
25-
#[not_covariant]
26-
engine: MainEngine<'this>,
27-
}
28-
2916
impl Implementation for Rsonpath {
30-
type Query = RsonpathQuery;
17+
type Query = MainEngine;
3118

3219
type File = OwnedBytes<Vec<u8>>;
3320

@@ -52,25 +39,20 @@ impl Implementation for Rsonpath {
5239

5340
fn compile_query(&self, query: &str) -> Result<Self::Query, Self::Error> {
5441
let query = rsonpath_syntax::parse(query).unwrap();
42+
let engine = MainEngine::compile_query(&query).map_err(RsonpathError::CompilerError)?;
5543

56-
let rsonpath = RsonpathQuery::try_new(query, |query| {
57-
MainEngine::compile_query(query).map_err(RsonpathError::CompilerError)
58-
})?;
59-
60-
Ok(rsonpath)
44+
Ok(engine)
6145
}
6246

6347
fn run(&self, query: &Self::Query, file: &Self::File) -> Result<Self::Result<'_>, Self::Error> {
64-
query
65-
.with_engine(|engine| engine.matches(file, &mut VoidSink))
66-
.map_err(RsonpathError::EngineError)?;
48+
query.matches(file, &mut VoidSink).map_err(RsonpathError::EngineError)?;
6749

6850
Ok("[not collected]")
6951
}
7052
}
7153

7254
impl Implementation for RsonpathCount {
73-
type Query = RsonpathQuery;
55+
type Query = MainEngine;
7456

7557
type File = OwnedBytes<Vec<u8>>;
7658

@@ -95,25 +77,20 @@ impl Implementation for RsonpathCount {
9577

9678
fn compile_query(&self, query: &str) -> Result<Self::Query, Self::Error> {
9779
let query = rsonpath_syntax::parse(query).unwrap();
80+
let engine = MainEngine::compile_query(&query).map_err(RsonpathError::CompilerError)?;
9881

99-
let rsonpath = RsonpathQuery::try_new(query, |query| {
100-
MainEngine::compile_query(query).map_err(RsonpathError::CompilerError)
101-
})?;
102-
103-
Ok(rsonpath)
82+
Ok(engine)
10483
}
10584

10685
fn run(&self, query: &Self::Query, file: &Self::File) -> Result<Self::Result<'_>, Self::Error> {
107-
query
108-
.with_engine(|engine| engine.count(file))
109-
.map_err(RsonpathError::EngineError)?;
86+
query.count(file).map_err(RsonpathError::EngineError)?;
11087

11188
Ok("[not collected]")
11289
}
11390
}
11491

11592
impl Implementation for RsonpathMmap {
116-
type Query = RsonpathQuery;
93+
type Query = MainEngine;
11794

11895
type File = MmapInput;
11996

@@ -138,25 +115,20 @@ impl Implementation for RsonpathMmap {
138115

139116
fn compile_query(&self, query: &str) -> Result<Self::Query, Self::Error> {
140117
let query = rsonpath_syntax::parse(query).unwrap();
118+
let engine = MainEngine::compile_query(&query).map_err(RsonpathError::CompilerError)?;
141119

142-
let rsonpath = RsonpathQuery::try_new(query, |query| {
143-
MainEngine::compile_query(query).map_err(RsonpathError::CompilerError)
144-
})?;
145-
146-
Ok(rsonpath)
120+
Ok(engine)
147121
}
148122

149123
fn run(&self, query: &Self::Query, file: &Self::File) -> Result<Self::Result<'_>, Self::Error> {
150-
query
151-
.with_engine(|engine| engine.matches(file, &mut VoidSink))
152-
.map_err(RsonpathError::EngineError)?;
124+
query.matches(file, &mut VoidSink).map_err(RsonpathError::EngineError)?;
153125

154126
Ok("[not collected]")
155127
}
156128
}
157129

158130
impl Implementation for RsonpathMmapCount {
159-
type Query = RsonpathQuery;
131+
type Query = MainEngine;
160132

161133
type File = MmapInput;
162134

@@ -181,18 +153,13 @@ impl Implementation for RsonpathMmapCount {
181153

182154
fn compile_query(&self, query: &str) -> Result<Self::Query, Self::Error> {
183155
let query = rsonpath_syntax::parse(query).unwrap();
156+
let engine = MainEngine::compile_query(&query).map_err(RsonpathError::CompilerError)?;
184157

185-
let rsonpath = RsonpathQuery::try_new(query, |query| {
186-
MainEngine::compile_query(query).map_err(RsonpathError::CompilerError)
187-
})?;
188-
189-
Ok(rsonpath)
158+
Ok(engine)
190159
}
191160

192161
fn run(&self, query: &Self::Query, file: &Self::File) -> Result<Self::Result<'_>, Self::Error> {
193-
query
194-
.with_engine(|engine| engine.count(file))
195-
.map_err(RsonpathError::EngineError)?;
162+
query.count(file).map_err(RsonpathError::EngineError)?;
196163

197164
Ok("[not collected]")
198165
}

0 commit comments

Comments
 (0)