How to save a zero copy in a native node module?

I am writing my own node module for a database in a process that has zero copies of data. I would like my module to also have this ability. In other words, when I get data from a database, I would like to transfer data to V8 without the need to copy memory or the need to parse something.

How can i do this?

So far, all the ways I've seen included either disassembling between JSON (pretty much empty resources in this case), or instantiating V8 data structures and copying the data into them.

NOTE. In case you are interested, a null instance of a data search means (in a nutshell) that the database engine does not need to copy memory when retrieving data.

+4
source share
1 answer

I think I found a solution, although it is rather limited.

Interesting documentation can be found here: https://developers.google.com/v8/ (review) and http://izs.me/v8-docs/main.html (API docs)

It seems that V8 has an ExternalStringResource class that can be used for this purpose:
http://izs.me/v8-docs/classv8_1_1String_1_1ExternalStringResource.html

Node itself also has a Buffer class, which can also be used for similar purposes:
http://nodejs.org/api/buffer.html

Using the two classes above, you can implement a null copy in your own node module for strings and byte arrays. Unfortunately, it seems that (at the time I'm writing this) this is not possible for objects.

EDIT

In case you have everything in order with a zero copy of the string or Buffer properties of the object (but not the whole object), it can be easily implemented using interceptors or accessories in the V8 API.

+3
source

Source: https://habr.com/ru/post/1480061/


All Articles