baruh
Overall, the performance in multiple places in the project I am working on has improved. However, there is one module that does a few operations that seems to - although it
doesn’t seem to - get slower between versions, actually experiencing 4-5x degradation (from 50-60 microseconds to 300 microseconds).
The example snippet of the code looks like
defmodule State do
use Agent
def start_link(opts \\ []) do
state = %{
id_availability: Keyword.get(opts, :available, true),
}
Agent.start_link(fn -> state end, name: Keyword.get(opts, :name, __MODULE__))
end
@spec available?() :: boolean()
def available?(agent \\ __MODULE__), do: get_opts(agent)[:id_availability]
@spec get_opts() :: map()
def get_opts(agent \\ __MODULE__) do
Agent.get(agent, & &1)
end
@spec set_opts(map()) :: :ok
def set_opts(agent \\ __MODULE__, opts) when is_map(opts) do
Agent.update(agent, fn _state -> opts end)
end
end
defmodule A do
def f1(struc, allowlist) do
if needs_extra_elements?(struc) do
%{
lista: struc.lista ++ ["a"],
listb: struc.listb ++ ["b", "c"],
keys: Map.take(struc.keys, allowlist)
}
else
struc
end
end
def needs_extra_elements?(struc) do
struc.has_lists? and String.ends_with?(struc.special_key, "aabbcc") and State.available?()
end
end
I’m not sure how this could result in 5x performance degradation. Any help would be greatly appreciated.
Trending in Questions
Hello everyone!
I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++.
Does anyone ...
New
I’m very new to Elixir, so sorry if this is a silly question:
I am wondering what happens to the mailbox of a process when the machine i...
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
Background
When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error:
* assembling mark...
New
I load tested a plain Phoenix chat app backed by Postgres with 100 million messages in it, everything on default settings, to see what br...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
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
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hi everyone :waving_hand:
I’ve been working on PhiaUI, an open-source UI component library for Phoenix LiveView, and I wanted to share i...
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
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #elixirconf-us
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #security
- #elixirconf-eu
- #processes
- #api
- #forms
- #hex










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
LostKobrakai
I cannot tell much about the performance degradation, but this isn’t a great way to use an agent. You should filter down the data within the agent callback and only return what is needed, which is then sent/copied to the caller. Currently you copy the whole agent state to the caller, to then there select a subset of the whole. In your example that likely doesn’t make a difference, but if your state is more involved in practise it might.
dimitarvp
Have you factually established that it’s exactly calling these functions that got slower with time?
baruh
Not yet, I did the change that @LostKobrakai suggested, because it seems an improvement, but definitely doesn’t explain the problem.
However I notice that there is and call to
which I am going to benchmark between the versions.
Actually after benchmark I can see
On the old elixir/erlang
The new elixir/erlang
It seems the problem is in
Plug.Conn.Cookies.decode/1with the same payload it gets 4x slower on the new version of elixir/erlang.We are using
:plug, "1.16.0";:plug_cowboy, "2.6.1";:plug_crypto, "2.1.0".baruh
@josevalim just released fix for that in
plug, "1.16.1"(more info GH-issue). The newest version is 3x faster than 1.14.3/24.3.2.8 withplug, "1.16.0".