sezaru

sezaru

I have some pretty big resources in my code base that takes more than 10 seconds to compile, after profiling it a bit, I noticed that the compile time would go down a lot if I remove the code_interface block from it.

For example, one of my resources have this code_interface:

    code_interface do
      define :create
      define :create_with_lead
      define :create_live_transfer
      define :create_fake
      define :create_with_photo_upload

      define :update
      define :photo_requred_now
      define :send_photo_upload_request
      define :request_photo_upload_from_seller
      define :modify_appointment

      define :cancel
      define :cancel_fake

      define :reschedule

      define :get
      define :get_admin
      define :get_own
      define :get_by_lead
      define :get_by_property_registry
      define :get_by_attom_id

      define :list_own
      define :list_between_dates
      define :list_admin
      define :list_by_address

      define :priors
      define :sign_appointment
    end

When compiling the resource with the code_interface, it would take around 11 seconds:

`[profile] 11260ms compiling + 0ms waiting while compiling lib/core/marketplace/ap/appointment.ex`

If I remove the code_interface, then it goes down to 2 seconds:

`[profile] 2270ms compiling + 0ms waiting while compiling lib/core/marketplace/ap/appointment.ex`

I also tried to move the code interface to the domain:

      resource Ap.Appointment do
        define :create_appointment, action: :create
        ...
        define :sign_appointment, action: :sign_appointment
      end

With this in the domain, the domain took 6 seconds to finish:

[profile] 6397ms compiling + 0ms waiting while compiling lib/core/marketplace/ap.ex

And without it, it would take only 285ms:

[profile] 285ms compiling + 0ms waiting while compiling lib/core/marketplace/ap.ex

So, here is the question, is this expected? Can this be optimized in some way? It took me by surprise how slower the compilation is when having a code interface (either in the resource or in the domain).

I’m literally considering remove all code interfaces from my code base to make it compile faster, but I would like to know if this is just a optimization “bug” that can be fixed or it is expected.

Showing Posts 1 to 7

zachdaniel

zachdaniel

Creator of Ash

Wow, that is pretty damn hefty!

Honestly I’d be willing to bet that we can optimize this. Could you perhaps put together a sample project showing these slow compile times? I could go in and hunt down problems and clean things up. One such example is that the code interface logic is not really the greatest macro code anyone ever wrote, I wrote it pretty early on and I know a lot more than I did back then :laughing:

sezaru

sezaru OP

Here it is @zachdaniel GitHub - sezaru/test_slow_code_interface · GitHub

To test it, you need to compile with profile set, basically run mix compile –profile time

Then, in the lib/test/my_domain.ex you can change the if to enable or disable the code interface definitions.

You can also do the same with the resource in lib/test/my_domain/my_resource.ex

Here are my numbers:

MyResource with code_interface:

[profile] 4148ms compiling + 0ms waiting while compiling lib/test/my_domain/my_resource.ex

MyResource without code_interface:

[profile] 533ms compiling + 0ms waiting while compiling lib/test/my_domain/my_resource.ex

MyDomain with code_interface:

[profile] 3719ms compiling + 0ms waiting while compiling lib/test/my_domain.ex

MyDomain without code_interface:

[profile] 368ms compiling + 0ms waiting while compiling lib/test/my_domain.ex

sezaru

sezaru OP

hey @zachdaniel any insights regarding this? Were you able to reproduce the issue with the project I created in the post above?

zachdaniel

zachdaniel

Creator of Ash

I’m hoping to look into this this weekend.

zachdaniel

zachdaniel

Creator of Ash

@sezaru should be some pretty significant improvements in main of ash. Please give it a shot and let me know the results :smiley:

DGollings

DGollings

For us trying out main was a massive improvement, from ~32s to ~9s, thanks @zachdaniel

sezaru

sezaru OP

Working great for the as-well! From 18 seconds in a resource to around 6s. Thanks again :slight_smile:

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
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
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

GenericJam
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
JesseHerrick
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
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
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
KristerV
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews