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

Add feature 'multithread' to use Rsonpath in multithread context #622

Merged
merged 3 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/rsonpath-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ test-case = { workspace = true }
default = ["simd"]
arbitrary = ["dep:arbitrary"]
simd = []
multithread = []

[[example]]
name = "approx_spans_usage"
path = "examples/approx_spans_usage.rs"
doc-scrape-examples = true

[lints]
workspace = true
workspace = true
13 changes: 9 additions & 4 deletions crates/rsonpath-lib/src/automaton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ use crate::{automaton::error::CompilerError, debug, string_pattern::StringPatter
use nfa::NondeterministicAutomaton;
use rsonpath_syntax::{num::JsonUInt, JsonPathQuery};
use smallvec::SmallVec;
use std::{fmt::Display, ops::Index, rc::Rc};
use std::{fmt::Display, ops::Index};

#[cfg(not(feature = "multithread"))]
use std::rc::Rc;
#[cfg(feature = "multithread")]
use std::sync::Arc as Rc;

/// A minimal, deterministic automaton representing a JSONPath query.
#[derive(Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Automaton {
states: Vec<StateTable>,
}
Expand All @@ -25,7 +30,7 @@ pub type MemberTransition = (Rc<StringPattern>, State);

/// Transition on elements of an array with indices specified by either a single index
/// or a simple slice expression.
#[derive(Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ArrayTransition {
label: ArrayTransitionLabel,
target: State,
Expand All @@ -44,7 +49,7 @@ pub(super) enum ArrayTransitionLabel {
///
/// Contains transitions triggered by matching member names or array indices, and a fallback transition
/// triggered when none of the labelled transitions match.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct StateTable {
attributes: StateAttributes,
member_transitions: SmallVec<[MemberTransition; 2]>,
Expand Down
3 changes: 3 additions & 0 deletions crates/rsonpath-lib/src/automaton/minimizer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! Determinization and minimization of an NFA into the final DFA used by the engines.

#[cfg(not(feature = "multithread"))]
use std::rc::Rc;
#[cfg(feature = "multithread")]
use std::sync::Arc as Rc;

// NOTE: Some comments in this module are outdated, because the minimizer doesn't
// actually produce minimal automata as of now - see #91.
Expand Down
7 changes: 6 additions & 1 deletion crates/rsonpath-lib/src/automaton/nfa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ use crate::{automaton::SimpleSlice, error::UnsupportedFeatureError, string_patte

use super::{error::CompilerError, ArrayTransitionLabel};
use rsonpath_syntax::{str::JsonString, JsonPathQuery, Step};
use std::{collections::HashMap, fmt::Display, ops::Index, rc::Rc};
use std::{collections::HashMap, fmt::Display, ops::Index};

#[cfg(not(feature = "multithread"))]
use std::rc::Rc;
#[cfg(feature = "multithread")]
use std::sync::Arc as Rc;

/// An NFA representing a query. It is always a directed path
/// from an initial state to the unique accepting state at the end,
Expand Down
4 changes: 4 additions & 0 deletions crates/rsonpath-lib/src/engine/head_skipping.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
//! Engine decorator that performs **head skipping** &ndash; an extremely optimized search for
//! the first matching member name in a query starting with a self-looping state.
//! This happens in queries starting with a descendant selector.

#[cfg(not(feature = "multithread"))]
use std::rc::Rc;
#[cfg(feature = "multithread")]
use std::sync::Arc as Rc;

use crate::{
automaton::{Automaton, State},
Expand Down
3 changes: 2 additions & 1 deletion crates/rsonpath-lib/src/engine/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ use smallvec::{smallvec, SmallVec};
///
/// The engine is stateless, meaning that it can be executed
/// on any number of separate inputs, even on separate threads.
#[derive(Debug)]

#[derive(Clone, Debug)]
pub struct MainEngine {
automaton: Automaton,
simd: SimdConfiguration,
Expand Down
Loading