Tips to speed up compile times?

As my resources have grown, my compile times have gotten irritatingly long. Any tips for improving them?
Solution:
```elixir defmodule Foo do use Ash.Resource.Change def change(changeset, opts, context) do...
Jump to solution
11 Replies
ZachDaniel
ZachDaniel5mo ago
fewer inline function changes can help You can also try using Spark.Dsl.Fragment to split up large resources
⿻ eileen
⿻ eileenOP5mo ago
Will give it a try 🫡 Are fragments supposed to help with compile times or is that more just for code organization?
ZachDaniel
ZachDaniel5mo ago
Was originally designed for code organization but i think they may help w/ compile times unverified 😄
⿻ eileen
⿻ eileenOP5mo ago
What is the syntax for using a module instead of an inline function in an after_transaction hook? I have my change module created with a batch_change callback defined, but I can't figure out how to use it in place of an inline function
ZachDaniel
ZachDaniel5mo ago
I don't think you need the batch_change
Solution
ZachDaniel
ZachDaniel5mo ago
defmodule Foo do
use Ash.Resource.Change

def change(changeset, opts, context) do
Ash.Changeset.after_action(changest, fn changeset, result ->
{:ok, result}
end
end
end
defmodule Foo do
use Ash.Resource.Change

def change(changeset, opts, context) do
Ash.Changeset.after_action(changest, fn changeset, result ->
{:ok, result}
end
end
end
⿻ eileen
⿻ eileenOP5mo ago
Sorry I'm still not getting this ... What does this look like in my resource action then?
change after_action(&AfterCompleted.change/3)
change after_action(AfterCompleted)
change after_action(&AfterCompleted.change/3)
change after_action(AfterCompleted)
These ^^^ don't work The first one returns a changeset when it's supposed to reutrn {:ok, result}. The second one is a module and it needs a function Bah, sorry - have a good 4th!
ZachDaniel
ZachDaniel5mo ago
Did you figure it out? Its just change AfterCompleted w/ a module that implements the Ash.Resource.Change behaviour
⿻ eileen
⿻ eileenOP5mo ago
OHHHHH Now I get it 😮 I do have a version working but it sucks Basicaly just an external module with a change/3 function that takes goes like this:
change after_transaction(&AfterCompleted.change/3)
change after_transaction(&AfterCompleted.change/3)
But now I'm seeing we can compose all our changes in one Change module. just clicked
ZachDaniel
ZachDaniel5mo ago
Ah, yeah so you can do it that way but generally speaking the "purest form" of it is change SomeModule that module can then implement various callbacks, add various hooks etc.
⿻ eileen
⿻ eileenOP5mo ago
I am levelling up on this independence day This "pure" form also seems to be the only one that actually impacts compilation times. Haven't investigated fragments yet but when this Change module compiles it does not trigger the calling resource to compile

Did you find this page helpful?