Skip to content

Commit

Permalink
Trying different approaches, such as exposing tapes (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
luizperes committed Apr 17, 2020
1 parent 398a38f commit 43edd6b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
32 changes: 30 additions & 2 deletions simdjson/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,8 @@ Napi::Value simdjsonnode::ParseWrapped(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
std::string json = info[0].As<Napi::String>();
try {

dom::parser parser;
return makeJSONObject(env, parser.parse(json));

} catch (simdjson_error &error) {
Napi::Error::New(env, error_message(error.error())).ThrowAsJavaScriptException();
return env.Null();
Expand All @@ -141,9 +139,39 @@ Napi::Object simdjsonnode::LazyParseWrapped(const Napi::CallbackInfo& info) {
return result;
}

Napi::Object simdjsonnode::BuffersWithParseWrapped(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
std::string json = info[0].As<Napi::String>();
dom::parser parser;
error_code error = parser.parse(json).error();
if (error) {
Napi::Error::New(env, error_message(error)).ThrowAsJavaScriptException();
return Napi::Object::New(env);
}
uint64_t *tapebuf = std::move(parser.doc.tape).release();
uint8_t *stringbuf = std::move(parser.doc.string_buf).release();
size_t tapebufsize = parser.current_loc;
size_t stringbufsize = parser.current_string_buf_loc - stringbuf;

This comment has been minimized.

Copy link
@luizperes

luizperes Apr 17, 2020

Author Owner

I have just updated it, @nojvek, thanks for letting me know!

See that even with that, I get:

apache_builds.json#simdjson x 4,463 ops/sec ±9.84% (68 runs sampled) => 0.224ms
apache_builds.json#JSON x 1,153 ops/sec ±34.30% (73 runs sampled) => 0.867ms
canada.json#simdjson x 149 ops/sec ±0.87% (76 runs sampled) => 6.715ms
canada.json#JSON x 40.26 ops/sec ±1.41% (51 runs sampled) => 24.836ms
citm_catalog.json#simdjson x 132 ops/sec ±0.50% (83 runs sampled) => 7.563ms
citm_catalog.json#JSON x 46.54 ops/sec ±11.28% (61 runs sampled) => 21.489ms
github_events.json#simdjson x 3,252 ops/sec ±0.57% (93 runs sampled) => 0.307ms
github_events.json#JSON x 1,362 ops/sec ±0.62% (92 runs sampled) => 0.734ms
gsoc_2018.json#simdjson x 156 ops/sec ±17.95% (57 runs sampled) => 6.404ms
gsoc_2018.json#JSON x 50.03 ops/sec ±7.30% (57 runs sampled) => 19.988ms
instruments.json#simdjson x 2,923 ops/sec ±1.56% (85 runs sampled) => 0.342ms
instruments.json#JSON x 901 ops/sec ±24.13% (78 runs sampled) => 1.109ms
marine_ik.json#simdjson x 103 ops/sec ±0.41% (75 runs sampled) => 9.674ms
marine_ik.json#JSON x 41.30 ops/sec ±1.16% (49 runs sampled) => 24.215ms
mesh_pretty.json#simdjson x 354 ops/sec ±1.57% (84 runs sampled) => 2.828ms
mesh_pretty.json#JSON x 135 ops/sec ±0.93% (81 runs sampled) => 7.430ms
mesh.json#simdjson x 520 ops/sec ±1.39% (78 runs sampled) => 1.925ms
mesh.json#JSON x 162 ops/sec ±20.42% (71 runs sampled) => 6.170ms
numbers.json#simdjson x 3,138 ops/sec ±0.63% (93 runs sampled) => 0.319ms
numbers.json#JSON x 884 ops/sec ±0.83% (90 runs sampled) => 1.131ms
random.json#simdjson x 374 ops/sec ±0.67% (83 runs sampled) => 2.671ms
random.json#JSON x 111 ops/sec ±2.27% (69 runs sampled) => 8.971ms
sf_citylots.json#simdjson x 1.13 ops/sec ±7.86% (7 runs sampled) => 884.743ms
sf_citylots.json#JSON x 0.44 ops/sec ±4.74% (6 runs sampled) => 2260.015ms
twitter.json#simdjson x 335 ops/sec ±1.05% (89 runs sampled) => 2.982ms
twitter.json#JSON x 99.33 ops/sec ±2.01% (73 runs sampled) => 10.067ms
twitterescaped.json#simdjson x 766 ops/sec ±7.44% (75 runs sampled) => 1.305ms
twitterescaped.json#JSON x 196 ops/sec ±35.87% (61 runs sampled) => 5.097ms
update_center.json#simdjson x 382 ops/sec ±0.82% (88 runs sampled) => 2.616ms
update_center.json#JSON x 115 ops/sec ±9.43% (69 runs sampled) => 8.692ms

filename filesize (MB) JSON.parse(ms) simdjson.lazyParse (ms) JSON.parse (GB/s) simdjson.lazyParse (GB/s) X faster
apache_builds.json 0.13 0.867 0.224 0.15 0.57 3.87
canada.json 2.25 24.836 6.715 0.09 0.34 3.70
citm_catalog.json 1.73 21.489 7.563 0.08 0.23 2.84
github_events.json 0.07 0.734 0.307 0.09 0.21 2.39
gsoc_2018.json 3.33 19.988 6.404 0.17 0.52 3.12
instruments.json 0.22 1.109 0.342 0.20 0.64 3.24
marine_ik.json 2.98 24.215 9.674 0.12 0.31 2.50
mesh_pretty.json 1.58 7.430 2.828 0.21 0.56 2.63
mesh.json 0.72 6.170 1.925 0.12 0.38 3.21
numbers.json 0.15 1.131 0.319 0.13 0.47 3.55
random.json 0.51 8.971 2.671 0.06 0.19 3.36
sf_citylots.json 189.78 2260.015 884.743 0.08 0.21 2.55
twitter.json 0.63 10.067 2.982 0.06 0.21 3.38
twitterescaped.json 0.56 5.097 1.305 0.11 0.43 3.91
update_center.json 0.53 8.692 2.616 0.06 0.20 3.32

Like I said, External seems to have a better performance

Napi::ArrayBuffer tapebufobj = Napi::ArrayBuffer::New(env, static_cast<void *>(tapebuf), tapebufsize,
[](Napi::Env /*env*/, void * obj) {
uint64_t *o = static_cast<uint64_t *>(obj);
delete o;
});
Napi::ArrayBuffer stringbufobj = Napi::ArrayBuffer::New(env, static_cast<void *>(stringbuf), stringbufsize,
[](Napi::Env /*env*/, void * obj) {
uint8_t *o = static_cast<uint8_t *>(obj);
delete o;
});
Napi::Object result = Napi::Object::New(env);
result.Set("tapeBuffer", tapebufobj);
result.Set("stringBuffer", stringbufobj);
return result;
}

Napi::Object simdjsonnode::Init(Napi::Env env, Napi::Object exports) {
exports.Set("isValid", Napi::Function::New(env, simdjsonnode::IsValidWrapped));
exports.Set("parse", Napi::Function::New(env, simdjsonnode::ParseWrapped));
exports.Set("lazyParse", Napi::Function::New(env, simdjsonnode::LazyParseWrapped));
exports.Set("buffersWith", Napi::Function::New(env, simdjsonnode::BuffersWithParseWrapped));
return exports;
}
2 changes: 2 additions & 0 deletions simdjson/bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ namespace simdjsonnode {
Napi::Value ValueForKeyPathWrapped(const Napi::CallbackInfo& info);
Napi::Value findKeyPath(Napi::Env env, std::vector<std::string> subpaths, dom::element pjh);

Napi::Object BuffersWithParseWrapped(const Napi::CallbackInfo& info);

Napi::Object Init(Napi::Env env, Napi::Object exports);
}

0 comments on commit 43edd6b

Please sign in to comment.