minhajuddin
Defmap is a utility which allows you to embed a map into a module for faster/easier lookups.
Trending in Announcing
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries.
offset-based pagination with...
New
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
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
Hi all!
I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas.
You...
New
Hello
Published a new library - ProcessHub!
ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
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
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
This showed up on my feed.. anyone heard of it? Just hype?
Ox Alpha is a reasoning model designed for coding, sustained ag...
New
It’s not that it’s vocabulary is too advanced. It’s something worse.
I get lost trying to follow even a paragraph written by Claude. It’...
New
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
OvermindDL1
Ah that’s cool.
Eiji
Can you explain me the reason of use macros in your project?
For me (I don’t see a special use case) it’s unnecessary. Instead of this I recommend to use ETS (Erlang Term Storage) or Agent.
For example look at example KV.Bucket implementation.
In my case library do not need to reserve
getmethod name and code is much more cleaner (at least for me).Your library also does not allow to override
Map.Can you agree with me or I missed something? What do you think about my comment?
Edit
One more example:
OvermindDL1
To me it looks like a way to define an immutable enumeration.
Eiji
Ok, how about my example in edit?
bbense
Well, there can be some performance advantages in functional heads vs just looking things up in a map. This is more or less the way unicode support is implemented in Elixir core.
I think I’d like this more if it did not use the Map
getas the function name and I’d really like it a lot more if it wasn’t called Defmap. The function is really justget_constant, or even justconstantorattribute. It’s a generic tool for exposing module attributes as functions. Map is just a convenient way to structure the input, you aren’t defining a Map in any practical sense at all.The only thing wrong with this is actually the hardest part of programming, naming stuff. I think what it does is useful.
minhajuddin
Thanks for all the feedback guys
I have benchmarked the simple map implementation from @Eiji
The difference is performance is not huge. However, there is a huge difference in memory usage. I checked the memory usage of the defmap version using
) and
:observer.start(Please recommend a good memory profiling tool, I didn’t know anydefmapused ~43mb of memory whereasplainmapused ~200mb, This was my initial assumption as for every lookup with the map implementation we are instantiating a full map and then selecting one value from it. You can checkout the test implementation @ GitHub - minhajuddin/defmap_test · GitHubEiji
Ok, now I see your point.
Thanks for performance testing, they give me a lot to think about.
I have a feature request:
more configuration - allow to send
optslike:to allow define multiple embed maps (also private maps) into one module with different callers.
Your default configuration
config.exs:minhajuddin
Thanks for the feedback
and ideas. I’ll add them soon
sasajuric
I’m not sure you need a lib and a macro for this. You can get the same thing with something like this (untested):
I occasionally use this technique.