tcoopman
I was reading the docs on Agent and noticed there is no mentions of hibernation at all.
Given that Agents are just wrappers around GenServers I was kinda surprised .
So I read through the code, but hibernate is not used at all.
Wouldn’t it make sense to support hibernate on Agent? I noticed that hibernation reduce memory consumption often a lot.
Trending in Discussions
Hey there,
It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
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
Hi there! :wave:
@frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
I’ve been using Emacs as my main code editor for more than a two years. It’s a custom build version although I’ve tried doom emacs and sp...
New
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
Lately I’ve been thinking about how to organize components as a LiveView application grows. One of the pain points I’ve found (for myself...
New
Other Trending Topics
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
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
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
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
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
Just published claude-code-elixir, a plugin marketplace for Claude Code with Elixir support. These are the plugins I’ve been using for my...
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
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex











Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dimitarvp
You would think so, yep, but I’d say if you have enough
Agents in memory that hibernating them would help you then you have a huge design problem. I mean, you would probably need 500K - 1M agents for this to make a tangible difference. And you absolutely should not have so many agents.tcoopman
I find that a bit of a weird argument.
You can make the same argument for GenServers and LiveViews.
GenServers support hibernate and LiveView has a default hibernation after 15s.
tcoopman
One more thing. It’s actually trivial to write an agent that grows huge in size if not hibernated and where hibernation makes it tiny again.
This will create a huge Agent named foo, although it might just have a tiny state.
After hibernation this would become tiny again.
You could of course trigger
:erlang.garbage_collecton it manually to get the same result.krasenyp
Yes, but the idea of an
Agentis not to fetch huge data in it. It’s for simple concurrent state management. You’d fetch the data and then update theAgent’s state. API’s should be hard to misuse.derek-zhou
IMHO, Agent is just GenServer with training wheels. I moved to full GenServer for all Agents except the trivial ones. Maybe the core team think adding advanced features to a “training-wheel” API is not worth their time?
tcoopman
That’s not an idea I read in the docs.
The docs say to consider if the data is large enough to require processing in the server.
It doesn’t say that you should not process large data in an agent.
Anyway, I don’t mind too much that
Agentdoesn’t have hibernate. I seem to be the first person missing this, and it’s easy enough to work around.I was a bit surprised about it though, because it’s easy to have big stacks that can be a lot smaller after garbage collection. Anyway, it might not be an issue at all and might be cleaned up once garbage collections kicks in.
D4no0
Completely agree, there is absolutely zero benefit from using an Agent over a Genserver besides those 2 callbacks that dump the state.
dimitarvp
Another angle to consider is that I personally would reach for ETS if load and/or payload size(s) start growing.
jeffheigl
@tcoopman - Agent supports hibernate_after, I just tried and confirmed it works (using :observer I looked that the Processes → Current Function).
When you call Agent.start_link just pass in the hibernate_after option in miliseconds.
Looking at the code, Agent.start_link will pass through the options to GenServer.start_link
https://github.com/elixir-lang/elixir/blob/main/lib/elixir/lib/agent.ex#L276