WallysFerreira
I’ve decided to do this year’s advent of code in elixir as my first approach to the language.
It’s been great but now on the second part of day 5 I’m facing a little problem.
When I try to run the code on iex, the process gets killed after a little while. I’ve done a little investigating and apparently the function “:lists.seq_loop/4” is using 1 gigabyte of memory and probably causing the system to shutdown the iex process.
I tried researching about memory management in elixir but only found out about :erlang.garbage_collect/0, and it didn’t make much difference.
If anyone could help with ideas to make the memory usage lower or any other ways to make it run, I’d gladly appreciate it
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
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
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
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
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
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
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
- #elixirconf-us
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
hauleth
Show us some code
WallysFerreira
hauleth
Check out the size of the ranges. You are trying to allocate gargantuantic lists and you are asking where you get the memory usage from. Answer lies in the amount of data that you want to store.
WallysFerreira
Yeah, I had taken the size of lists in consideration when writing the solution for the first part but totally forgot about that for this second part. I’ll write some code that doesn’t use lists. Thanks
stevensonmt
You can usually get some benefit from changing
EnumtoStreamcalls as theStreamfunctions are lazy and do not allocate all that memory up front with each call.WallysFerreira
Oooh that’s great. I’ll give it a try
WallysFerreira
Using Streams apparently didn’t cut it. I’ll just not use lists. Thanks anyways
schneebyte
I had the same problem, took a while to figure out. Had to think in terms of ranges and not individual numbers.
al2o3cr
General tip about AoC problems: a favorite “part 2” tactic is to expand the problem in a way that makes inefficient solutions intractable. For instance, the solution for my day 5 part 2 was ~15 million so
locationswould likely be LARGEThere’s another one later on this year where the straightforward “generate and count” approach fails even more spectacularly - with my input, a counting approach would have taken quite a while to count to 15 trillion!
IMO this is the best part of AoC, since usually it takes months / years of “production” use to find out an algorithm is inefficient.
stevensonmt
Yeah when the ranges are massive even lazy evaluation is going to eat up memory. Like others have said, thinking in terms other than evaluating each item is key for this sort of problem.