Strategies to make resources compile faster

I was having a discussion with my team in my daily job yesterday and we talked a little bit about how Ash improved our productivity, etc. One negative point that was brought up was that we feel that our project take a lot of time to compile some of our resources (some of them take more than 30 seconds).

That made me wonder if there are some best practices and tips to make the resources as lightweight as possible.

One thing that I think slow down compilations (it is a guess, I didn’t test it out to confirm it or not), is adding has_many to resources even if we don’t actually use the relationship anywhere (for example: An User can have one Role, so we add a belongs_to to it, but then, the Role can have many users, so we add a has_many to it event though we never actually access the users from the Role resource).

So, is there some best practices, and tips and tricks to improve resource compilations?

I have no idea if this affects compilation time but I’m a big advocate of not doing this. This is really no different than having “just in case” code/unused public functions. It can also lead to things like people preloading out of convenience when they shouldn’t be.

2 Likes

Lots of people think premature optimization is just about performance, but most of the time it falls in this category, building for a future that never will happen. It’s as destructive as early abstraction. Dead code has no place in your codebase, regardless of what the future holds.

The biggest thing you can do here is to remove as many anonymous functions from your resources as possible and extract them into module changes/preparations etc.

1 Like

Actually, none of my changes/preparations uses anonymous functions, they are already all inside modules.

Do breaking the resource into fragments help in any way?

I’ve heard that it can yes but I haven’t confirmed it personally.

I had this same sort of problem and came up with ash_profiler | Hex

There’s an incredible amount of solving that goes on when you don’t go out of your way to break up resources

2 Likes

That is really cool. I have an ERP in Ash that will definitely benefit from it. Seems like your Git repo is either private or wrong URL?

This is amazing, I will try it out ASAP! Btw, seems like the github repo doesn’t exist.

Sorry about that, was moving a bunch of projects into a new org so i could publish:

There you go. This ones for the devs that have over 30 attributes in an Ash Resource

1 Like