Zero-copy deserialization in Julia
scattered-thoughts.net
scattered-thoughts.net
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....
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
I've done this in Java to do cache aware reading to pretty great success.
* https://github.com/ExpandingMan/Arrow.jl
* https://arrow.apache.org/blog/2017/08/08/plasma-in-memory-ob...
Blobs is less a data-format and more a replacement for C's ability to cast arbitrary memory locations to structs.
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....
https://github.com/frankmcsherry/abomonation
It still needs me to opt in to declaring methods as unsafe, rather than automatically surfacing my uses of unsafe. I could definitely "trick users" by not doing that and pretending it always works (it doesn't).