minhajuddin
Defmap - embed maps into a module for faster/easier lookups. Feedback please
Defmap is a utility which allows you to embed a map into a module for faster/easier lookups.
Trending in Announcing
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly.
One of i...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
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
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
Hello,
I’m sharing my plugin here in forum after some time so it has time to mature and proof yourself.
I use Claude Code daily on a pr...
New
Other Trending Topics
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
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
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
We want to introduce a new native datatype to Erlang: native records. Although replacing all tuple records with native records is not our...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog
It says that Fly is going all-in on sprites, which is a worry ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #performance










First 9 of 9 Posts
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.