ketupia
Marlus presented techniques for optimizing liveview. One of his last points was to batch socket updates (timestamp 25:55).
All I’ve imagined so far is updating a structure in the socket that the view doesn’t use and then copying it to the active socket assigns peridoically. How would you approach this?
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m aware of 2 such projects, are there others?
git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
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
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used?
I’ve got two Github accoun...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
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
(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
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
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #elixirconf-us
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #security
- #elixirconf-eu
- #api
- #forms
- #performance










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
rhcarvalho
Hi! That presentation is really great, right? I don’t have access to the code, but from what I could see (watching again the relevant part) is:
Batchermodule that implements anon_mounthookhandle_event(could also do the same forhandle_info…)on_mount/1andattach_hook/4for how to accomplish the above:handle_eventlifecycle hook callsmodule.handle_batchwith a similar signature to the original either after a given number of items are collected or a timeoutBatcheris a behaviour that declares thehandle_batchaboveI could imagine implementing the above with no external dependency. Maybe something like GenStage — gen_stage v1.3.2 or Broadway — Broadway v1.3.0 can be useful for more complex cases.
A question might be where to store the current batch items. I think there are a few options:
Socket.privateusingput_private/3, so that changes are not trackedGenServerrhcarvalho
Here’s a single file demo implementation:
(also available as a GitHub Gist: Phoenix LiveView event batching · GitHub)
ketupia
First off - very nice and clean!! Thank you!
Your solution exposed me to a couple of facilities I hadn’t encountered before like LiveView.attach_hook and LiveView.put_private.
hlx
This might help you in the future
https://github.com/phoenix-playground/phoenix_playground
ketupia
Well that’s fun and - bonus - now I know you can run Phoenix LiveView from Live Book!
ketupia
I’ve reworked my version a bit. Thanks again to rhcarvalho. I couldn’t have done this without your version.
I realized I needed
Since the msg param of handle_info can be data of any shape, I added a callback to know when to throttle. The callback can use pattern matching or any other means.
Actually the first message and any other message when a batch hasn’t been processed since the timeout.
Let’s say the timeout is 500ms and 1000ms goes by since the last batch. The next message should be released immediately.
Here’s my updated version.