Skip to content

Commit

Permalink
first very naive implementation for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mmomtchev committed May 4, 2024
1 parent fcc1629 commit f306589
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

### [1.1.0] 2024-04-26
## [1.2.0]

- Implement a solution to [#110](https://github.com/mmomtchev/everything-json/issues/110), report allocated memory to the GC

## [1.1.0] 2024-04-26

- Pre-built binaries for macOS 14 / ARM64
- Update `simdjson` to 3.9.1
Expand Down
10 changes: 8 additions & 2 deletions src/JSON.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ JSONElementContext::JSONElementContext(const JSONElementContext &parent, const e

JSONElementContext::JSONElementContext() {}

JSON::JSON(const CallbackInfo &info) : ObjectWrap<JSON>(info) {
JSON::JSON(const CallbackInfo &info) : ObjectWrap<JSON>(info), external_memory(0) {
Napi::Env env(info.Env());

if (info.Length() != 1 || !info[0].IsExternal()) {
Expand All @@ -28,9 +28,15 @@ JSON::JSON(const CallbackInfo &info) : ObjectWrap<JSON>(info) {
store_json = context->store_json;
store_get = context->store_get;
store_expand = context->store_expand;
// This overreports memory to the GC
external_memory = input_text->length() * 2;
Napi::MemoryManagement::AdjustExternalMemory(env, external_memory);
}

JSON::~JSON() {}
JSON::~JSON() {
Napi::MemoryManagement::AdjustExternalMemory(Env(), -external_memory);
external_memory = 0;
}

shared_ptr<padded_string> JSON::GetString(const CallbackInfo &info) {
Napi::Env env(info.Env());
Expand Down
3 changes: 3 additions & 0 deletions src/jsonAsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ class JSON : public ObjectWrap<JSON>, JSONElementContext {
static void ProcessRunQueue(uv_async_t *);

static Function GetClass(Napi::Env env);

private:
int64_t external_memory;
};

#define TRY_RETURN_FROM_STORE(store, el) \
Expand Down

0 comments on commit f306589

Please sign in to comment.