jasonmonroe

jasonmonroe

I am building an application which compiles new functions based on user input. For performance reasons, I would like to compile each function separately since there will be a large quantity of functions which can change individually. I already have the application working with Module.create and :ets lookups for the modules; however, I know that the design is not ideal since the module names are dynamic. This means I am creating atoms based on user input which is obviously bad.

From what I can tell, there is no way to recompile only a piece of a module which requires me to separate out the functions. I would like to avoid polluting the atom table in this way so I have come up with a possible solution.

My current idea is to create a registry process which assigns atoms to functions which they can use for their modules. As functions are removed, the atom it was assigned would be freed for the next created function to use. This way I will limit the atoms I use to the most atoms I used at any one point in time. I know entirely how I would build this but I would love to find a more elegant way of doing it.

Any suggestions would be greatly appreciated.

Showing Posts 1 to 6

axelson

axelson

Scenic Core Team

Could you rework things to use just dynamically created functions instead of actual modules? I believe that would make it a lot easier.

jasonmonroe

jasonmonroe OP

Hi Axelson,

Thanks for the suggestion. For my scenario I am looking to run these functions at a really high rate and performance/throughput is my #1 goal. The benefit of compiling in my scenario is that my running processes can actually call the function directly through a naming convention rather than looking them up using an expensive process call.

To elaborate a little bit, I would like to be able to recompile an individual function while heavy execution is happening. So I need to optimize in 2 areas: execution and compilation with an emphasis on execution. If I have to send a process message to get an in-memory function, I’m certain I will be sacrificing performance.

axelson

axelson

Scenic Core Team

Sounds like an interesting use-case! Seems similar to discord’s fastglobal, although you’d probably can’t use it directly since it’s made for storing/accessing static data, but you could probably find inspiration there:

https://github.com/discordapp/fastglobal

Do you need to return the new results immediately or can you still run the old function while the execution is happening?

Also I’d recommend that you try multiple approaches and benchmark them (e.g. with benchee | Hex)

jasonmonroe

jasonmonroe OP

This is a great suggestion, I’ll look into this tomorrow and share how it goes. I’ve used Benchee for similar tests but I haven’t checked out the fastglobal code.

To make things more complicated, I actually need to store multiple versions of the functions to provide staged changes and rollback capabilities for groups of functions. I have a version of this working already, just looking to improve/innovate on it a bit.

jasonmonroe

jasonmonroe OP

Just to share my result: I looked at the fastglobal code and realized this is a small part of what I am already doing. It was fun to see I came up with the same strategy through my own testing. However, I’m assuming Discord was not using dynamic value names so it doesn’t solve that problem exactly. I know what I am trying to solve is very niche but I have some direction already on how to limit the atom usage.

chrismcg

chrismcg

Discord moved away from fastglobal according to We've since ditched fastglobal actually, as we found that it'd take too long to ... | Hacker News their reasons might be relevant to what you’re doing.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
psy-q
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews