reddit / emacs

plists, JSON or Redis for emacs?

vfclists · 2022-08-02 16:44
I have start using `alists` then `plists` for managing some of my data in Emacs and they seem quite slow, especially with `plists`, but I'm not sure where the delay is and I may be using it an inefficient manner. All I know is that for the small amounts of data involved it is not as fast as I expect, and in any case I expect my data to grow beyond its capabilities. Since `plists` and `JSON` look pretty much alike do guys think that managing the data with `JSON` may be a good idea? I was going to talk about redis but learned that redis doesn't use JSON as its native data format, but can use the JSON data format as well. Are there some external modules that Emacs can them with for better performance? How much data can `savehist` handle efficiently? I have a feeling I may be abusing it for something it is not intended for.
Axeman12 · 2022-08-02 16:58
Well, the reason that p-lists are slow is because they're *lists* and not hash tables. Emacs has hash tables, too, for bigger or performance critical data. The function `make-hash-table` creates a new one and `puthash` associates a key to a value.
ieure · 2022-08-02 17:05
Both alists and plists are linked lists, so they have O(n) lookup performance. JSON is an over-the-wire representation, which has nothing to do with in-memory performance. If you deserialize JSON with Emacs, it ends up as lists, so it'll perform *worse* than plain plists, because you're adding the de/serialization overhead on top of the O(n) performance that you already think is too slow. How much data are you working with? How does it perform? What is acceptable performance? You need to actually think about these before flinging random solutions at your problem. Lisps have used lists for decades, and while O(n) isn't great, computers are stupidly fast these days. I wouldn't expect this to be a bottleneck unless you're working with 100ks of entries in a single list.
arthurno1 · 2022-08-02 20:56
> I'm not sure where the delay is and I may be using it an inefficient manner. Without seeing your code, it is impossible to tell. Emacs has a[ profiler included](https://www.gnu.org/software/emacs/manual/html_node/elisp/Profiling.html), you might wish to take a look at it. > for the small amounts of data involved it is not as fast as I expect Define "small" and "fast". What is "small" for you and how "fast" do you expect it to be? Probably up to few tens or hundreds of items, it shouldn't matter; you should be good with linked list. > do guys think that managing the data with JSON may be a good idea? Depends on what you do with your data. If it is supposed to be produced and consumed by Emacs, the answer is definitely no. > Are there some external modules that Emacs can them with for better performance? How would that help you? Emacs works with lists internally in many places, so whichever data structure you would use, you will translate to and from Emacs internal representations for processing, which are often lists. Instead, rather look at other data types that Emacs offers you. You probably number one to go should be [hash map](https://www.gnu.org/software/emacs/manual/html_node/elisp/Hash-Tables.html). Alternatively, look at [arrays](https://www.gnu.org/software/emacs/manual/html_node/elisp/Arrays.html). But before you change your code and data structures, profile your code! Maybe the bottleneck is not the linked list data structure at all.