jsm

jsm

Package: module_store | Hex
Source: GitHub - juulSme/ModuleStore: Compiled-at-runtime modules as high-read-performance key-value stores in Elixir · GitHub
Docs: ModuleStore v0.0.1 — Documentation

I’ve created a small library that (mis)uses module (re)compilation to create very fast runtime storage. It performs extremely well for reads and extremely badly for writes, by design. The API is a simple key-value interface. It should be considered as being in a very early state, it’s not battle-tested at all at this point.

https://github.com/juulSme/ModuleStore

Showing Posts 1 to 10

ltd

ltd

Is there a reason to not use the erlang builtin :persistent_term.

https://www.erlang.org/doc/apps/erts/persistent_term.html

jsm

jsm OP

I’m aware of :persistent_term :slight_smile: it’s quite similar of course. The difference is that persistent term is global, and you have to namespace your items by using tuple keys. Here you can have one or more module stores with just your stuff, which is nice. Your code will read MySpecialStore.get(... and it’s absolutely the fastest possible thing to have, which is also nice. Apart from writes of course :stuck_out_tongue:

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

To be clear modules are also global. If you want a similarly ergonomic API you could just write a wrapper function around the persistent term lookup. As someone’s done a lot with compiled modules in Absinthe persistent term is just so much better.

jsm

jsm OP

Thanks for the feedback and taking an interest :slight_smile: can you elaborate on the problems you encountered? Do you have reason to believe this approach won’t work or cause problems under real world conditions? I know you can’t store everything this way, like refs.

I’m aware modules are global too. But we still consider MyAppWeb.Endpoint to be my endpoint, as opposed to Phoenix.Endpoint, and it has its own config. So I was thinking among those lines.

LostKobrakai

LostKobrakai

:persistent_term was added in response to people creating modules at runtime to store data. It explicitly is an api to replace what you’re doing with a native api, which gives the otp team a bit of control over the usecase over abusing unrelated apis around modules.

Namespacing shouldn’t really prevent you from using :persistent_term either.

jsm

jsm OP

Ah I hadn’t realized that. I thought I was doing something similar but with slightly different runtime characteristics. I figured it would be a nice little self-contained thing to contribute back, just trying to help out. It seems I’m reinventing the wheel in a way that is less round then the original so it’s probably best to pull the lib :frowning:

jsm

jsm OP

Then again, I the benchmark results do return some different results for compiled module vs persistent_term, especially with regards to the standard deviation (if the difference is significant is another question of course). That’s why I figured there might be a case for it.

I guess my question is: will this go horribly wrong in some way that I’m missing? If so, I’m really not to proud to pull the lib. If not, then why can’t this be out there as an alternative, apart from the fact that this is not what the compiler is meant to do?

stevensonmt

stevensonmt

If we’re discussing abusing features of the language have you benchmarked against using the process dictionary? Using it for configs is specifically called out as a possible appropriate use case in this post:

Write-once process parameters . Think of this as an initial configuration step. Stuff all the settings that will never change within a process in the dictionary. From a programming point of view they’re just like constants, so no worries about side effects.

wojtekmach

wojtekmach

Hex Core Team

For some more prior art, also check out GitHub - discord/fastglobal: Fast no copy globals for Elixir & Erlang. · GitHub. But yeah, I believe persistent_term was designed to solve problems like these.

jsm

jsm OP

That’s really interesting, thanks for the link :slight_smile:

Where Next? Top

Trending in Announcing Top

type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
kip
I’ll shortly be launching Text, a nascent text analysis library. Current functionality In this early version (not ready for prime time) ...
New
kip
Following on from my CLDR lbraries I started work on Unicode transforms. But like everything related to CLDR there is a lot of yak-shavin...
New

Other Trending Topics Top

budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews