sezaru
So, I’m importing millions of rows in my system to a resource that has some fields (around 7 fields) that are embedded resources.
I’m inserting the fields using bulk_create with chunks of 10_000 rows.
I noticed that this operation was kinda slow, it takes around 36 seconds to insert the 10_000 rows.
I suspected that the issue could be because of the embedded resources, so I removed them and replaced with fields directly in the main resource.
After that, the same bulk_create call takes 6 seconds to do the same work.
So, it seems that a embedded resource creates a big overhead when inserting a bunch of data.
Zack, do you think there is something that can be done to improve that, or that overhead is to be expected?
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,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
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
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
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
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
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
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
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
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zachdaniel
This definitely strikes me as something that should be fixable. It’s possible that the overhead is in the data layer itself, but I think that is probably unlikely. I would need to investigate further, and may not have time to do that this week. You can confirm that the performance issue is Ash by orchestrating a similar operation with bare ecto if you have some time
sezaru
I will try that when I have some free time and report back to you
zachdaniel
So, someone else reported a similar issue with casting embedded resources. I hope to have some time to look into it later this week.
barnabasJ
I had a similar issue. I had a calculation in which I made an API request and used a resource with Ash.DataLayer.Simple to convert the data in the response into a list of Ash Resources to have nice Graphql types.
The Resource in question also had a couple of embedded resources and also nested embedded resources. This was also really slow.
The only way I was able to get it to a reasonable timeframe was to do all the conversions myself and create the structs for the embedded resources myself before passing the data to
API.bulk_createwith theassume_casted?: trueoption.zachdaniel
Alright, beginning to look into this issue. There is definitely a significant slow down on embedded resource casting
zachdaniel
Okay so I’ve made some performance improvements. They are still much slower than raw maps, but if you guys could try it out and report back, that would be great. Performance improvements are in main. If you update ash to main, make sure to update
ash_postgresandash_graphqlalso.barnabasJ
After getting everything working with ash/main again, I can say that our calculation is now about 3x faster than before.
zachdaniel
Thats progress! Are you still having to manually create the embedded resources?
barnabasJ
I do for now, as I’m still using
assume_casted?: truefor the bulk_create. Casting ist still taking up too much time in this specific instance.I just finished upgrading, so I haven’t done any extensive testing yet but here is what I have right now.
I have these 2 reads, the first one is what I tried first but wasn’t fast enough.
I did a little testing with benchee, running the actions with the same list of 7 options each, so I don’t think bulk_create should a lot of optimization there.
Reading with doing the casting:
Takes around 10ms
vs
Preparing the input myself + doing this read action
Takes around 1ms
The thing with
assume_casted?: trueis that the embedded resources already need to be the real Ash.Resource structs. It might be nice to have an option where it would turn the maps into the structs but wouldn’t cast the values for it.zachdaniel
Interesting…I definitely want to track down the main slow down. I think there is likely just some unnecessary work being done there.