What's the fastest way to persist EDN data to file, and load it back?

I use pr-str to generate string form of EDN and save it to a file. However, there might be a chance that EDN file get really huge and text manipulating is too slow for that. Is there any means in Clojure(Script) that we dump the data into binary and put that into a file immediately? Would that be faster than using pr-str and read or read-string?

1 Like

I love nippy, although it’s clojure only (not cljs).

A good format for serializing Clojure data structures is Transit. It’s great for network communication, or for storing data in files.

JSON+Transit is a great fit for ClojureScript, because it makes use of the fast JSON de/encoders built into today’s JS engines.

I’d recommend looking at Transit and seeing if it’s fast enough before jumping to binary serialization formats (which always bring complexity).

See this discussion on the advantages/disadvantages of EDN vs Transit: https://groups.google.com/forum/#!msg/clojure/9ESqyT6G5nU/0RaZ3nkiJ3YJ


If it is meant to produce Clojure data structures, how can it take advantage of Json de/encoders built into the languages?

The answer to your question is at the other end of the link that @pesterhazy posted in his reply.

Sorry but I read the readme several times, I even read the code and I still don’t get the point

In the discussion to which @pesterhazy linked – which is not, and does not have a README – Alex Miller discusses the engineering decisions that went into Transit, which is why Paulus linked that discussion here. Transit encodes EDN into a format that can be set to be compatible with (i.e. implemented on top of) JSON because browsers have well tuned code written in C/C++ to parse JSON, from which Transit benefits. It can also target msgpack, &c.

Ok, I was missing the discussion link. However some of your words were key to make me understand something: that transit can be implemented on top of Json, they are somewhat compatible. But, Transit it is not a library to faster parse data which is already JSON (on the classic sense) to Clojure data structures

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.