Skip to content

Commit

Permalink
Added Document type
Browse files Browse the repository at this point in the history
I noticed that simd-json was still incredibly fast even without simd
enabled. The Document type is my last effort at making a mostly-safe
JSON parser.

The Document type parses into a single Vec, which is advantageous for
nested payloads due to having less tiny allocations. The downside is
that it takes a little more work to traverse the parsed document than
the Value type.

I've implemented a lot of convenience methods to facilitate moving
between Documents into Values, since the Value type is the only type
that supports being transformed back to JSON currently.

The major change in this commit is moving the parsing logic into its own
module and sharing it between the Document and Value types. This also
led to me publishing that event-driven parser module.
  • Loading branch information
ecton committed Jan 19, 2023
1 parent 0abc3a1 commit 746a37d
Show file tree
Hide file tree
Showing 8 changed files with 1,416 additions and 722 deletions.
16 changes: 16 additions & 0 deletions benchmarks/benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ fn justjson_parse(json: &str) -> justjson::Value<&str> {
justjson::Value::from_json(json).unwrap()
}

fn justjson_parse_doc(json: &str) -> justjson::doc::Document<'_> {
justjson::doc::Document::from_json(json).unwrap()
}

fn serde_json_value_parse(json: &str) -> serde_json::Value {
serde_json::from_str(json).unwrap()
}
Expand All @@ -38,6 +42,10 @@ fn justjson_parse_bytes(json: &str) -> justjson::Value<&str> {
justjson::Value::from_json_bytes(json.as_bytes()).unwrap()
}

fn justjson_parse_doc_bytes(json: &str) -> justjson::doc::Document<'_> {
justjson::doc::Document::from_json_bytes(json.as_bytes()).unwrap()
}

fn serde_json_value_parse_bytes(json: &str) -> serde_json::Value {
serde_json::from_slice(json.as_bytes()).unwrap()
}
Expand All @@ -47,10 +55,18 @@ fn bench_with_input(mut group: BenchmarkGroup<'_, WallTime>, input: &str) {
b.iter(|| justjson_parse(black_box(input)));
});

group.bench_function("justjson/doc/str", |b| {
b.iter(|| justjson_parse_doc(black_box(input)));
});

group.bench_function("justjson/bytes", |b| {
b.iter(|| justjson_parse_bytes(black_box(input)));
});

group.bench_function("justjson/doc/bytes", |b| {
b.iter(|| justjson_parse_doc_bytes(black_box(input)));
});

group.bench_function("serde-json/str", |b| {
b.iter(|| serde_json_value_parse(black_box(input)));
});
Expand Down
Loading

0 comments on commit 746a37d

Please sign in to comment.