Live data from Hacker News

Zero-copy deserialization in Julia

scattered-thoughts.net

11–20 of 34 posts

Re: Zero-copy deserialization in Julia

#11

That kind of reminds me of dumpable [1] library doing a similar thing in C++. [1] https://github.com/ipkn/dumpable

Huh, yeah, this is surprisingly similar, even down to needing a custom pointer type to do the offsetpointer conversion - https://github.com/ipkn/dumpable/blob/master/dptr.h#L64-L69

Re: Zero-copy deserialization in Julia

#14
I suppose the real Julia trick used to make this nice is the generated function. There isn’t really anything like this in C without code generation.

Other languages with macros can do this sort of thing but one then needs to “derive blob” or something like that.

In Haskell one could probably do it with Generic (ie the compiler generates a data representation of the type; you write a function to go from this representation to your deserialisation function; and then the compiler does a crazy amount of inlining)

An alternative way to do this in an object oriented language is with a different metaclass that does the appropriate dereferencing. But this risks being slow if not compiled well

Re: Zero-copy deserialization in Julia

#15
post #13

So, I have to check that libraries don't do this if I am to rely on the idea that Julia offers safety?

if that worries you, I wouldn't look under the covers of almost any database you run, nor network stack you have.

Graphics card drivers are WAY out. File systems too.

Julia offers as much safety as most languages. You would be hard pressed to find a language which doesn't let you pull something like this.

Julia wouldn't solve the 2 languages problem if there was a lot of things you would have to drop back to C to do....

Re: Zero-copy deserialization in Julia

#16
This reminds me of the OCaml "Ancient" library[1] that I wrote. It lets you have an extra heap of OCaml objects which can be stored in an mmap'd file and even shared between processes (although the sharing must be read-only and has a number of problems like everything has to be mapped at the same address which conflicts with ASLR - we didn't use pointeroffset conversion as done in this article because it would touch every page and you'd end up with no sharing).

I originally wrote it to analyze large data sets (where "large" meant 16+ GB which was much larger than the commonly available RAM at the time).

It integrated nicely with OCaml. You could create ordinary OCaml objects then incrementally "mark" them so those objects would be moved (recursively) into the ancient heap. The objects could still be accessed as if they were ordinary OCaml objects even if they were on the ancient heap. On the other side you could mmap a previous heap and access the objects as if they were regular OCaml objects directly (with a few shortcomings - see README). Depending on your access pattern this worked well even if available RAM was much smaller than the size of the data set.

[1] http://git.annexia.org/?p=ocaml-ancient.git;a=blob;f=README....

Re: Zero-copy deserialization in Julia

#17
post #16

This reminds me of the OCaml "Ancient" library[1] that I wrote. It lets you have an extra heap of OCaml objects which can be stored in an mmap'd file and even shared between processes (although the sharing must be read-only and has a number of problems like everything has to be mapped at the same address which conflicts with ASLR - we didn't use pointer offset conversion as done in this article because it would touch…

I used Ancient years ago for https://github.com/jamii/texsearch to stop the GC pauses caused by pointlessly traversing the huge immutable index. I don't know how else I would have met the latency requirements. Thanks for writing it :)

Re: Zero-copy deserialization in Julia

#18
تتمكن من خلال التواصل مع موقع مكتبتك الحصول علي العديد من الانواع المختلفة للتقنيات العالية في الجودة تقدم علي يد فريق عمل محترف ذات خبرة متميزة http://www.maktabtk.com/services.html http://www.maktabtk.com/

Re: Zero-copy deserialization in Julia

#19

I suppose the real Julia trick used to make this nice is the generated function. There isn’t really anything like this in C without code generation. Other languages with macros can do this sort of thing but one then needs to “derive blob” or something like that. In Haskell one could probably do it with Generic (ie the compiler generates a data representation of the type; you write a function to go from this represent…

Also being able to remove all the dispatch and stack-allocate everything. Haskell would probably do a good job of that too but in python or js, even with codegen, it would be hard to avoid heap allocation. The simple examples here might fall to escape analysis, but in production code the intermediate Blob values typically cross a lot of function boundaries.
Post reply on HN