Skip to content

Commit 746a37d

Browse files
committed
Added Document type
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.
1 parent 0abc3a1 commit 746a37d

8 files changed

Lines changed: 1416 additions & 722 deletions

File tree

benchmarks/benches/benchmarks.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ fn justjson_parse(json: &str) -> justjson::Value<&str> {
2121
justjson::Value::from_json(json).unwrap()
2222
}
2323

24+
fn justjson_parse_doc(json: &str) -> justjson::doc::Document<'_> {
25+
justjson::doc::Document::from_json(json).unwrap()
26+
}
27+
2428
fn serde_json_value_parse(json: &str) -> serde_json::Value {
2529
serde_json::from_str(json).unwrap()
2630
}
@@ -38,6 +42,10 @@ fn justjson_parse_bytes(json: &str) -> justjson::Value<&str> {
3842
justjson::Value::from_json_bytes(json.as_bytes()).unwrap()
3943
}
4044

45+
fn justjson_parse_doc_bytes(json: &str) -> justjson::doc::Document<'_> {
46+
justjson::doc::Document::from_json_bytes(json.as_bytes()).unwrap()
47+
}
48+
4149
fn serde_json_value_parse_bytes(json: &str) -> serde_json::Value {
4250
serde_json::from_slice(json.as_bytes()).unwrap()
4351
}
@@ -47,10 +55,18 @@ fn bench_with_input(mut group: BenchmarkGroup<'_, WallTime>, input: &str) {
4755
b.iter(|| justjson_parse(black_box(input)));
4856
});
4957

58+
group.bench_function("justjson/doc/str", |b| {
59+
b.iter(|| justjson_parse_doc(black_box(input)));
60+
});
61+
5062
group.bench_function("justjson/bytes", |b| {
5163
b.iter(|| justjson_parse_bytes(black_box(input)));
5264
});
5365

66+
group.bench_function("justjson/doc/bytes", |b| {
67+
b.iter(|| justjson_parse_doc_bytes(black_box(input)));
68+
});
69+
5470
group.bench_function("serde-json/str", |b| {
5571
b.iter(|| serde_json_value_parse(black_box(input)));
5672
});

0 commit comments

Comments
 (0)