Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Massive compile-time issues since we use a lot of fields in params #118

Open
mlankenau opened this issue Jan 30, 2019 · 13 comments
Open

Massive compile-time issues since we use a lot of fields in params #118

mlankenau opened this issue Jan 30, 2019 · 13 comments

Comments

@mlankenau
Copy link

We changed our maru services so that we define the data-structure in params instead of receiving just a Map.

We really like that it is checking the data that is received and that we get atom keys for all maps, but the compile time has increased massively.

Looking at the maru code it looks like a lot of things are going on in the param-definitions. Is there a change to speed up the macro execution?

@falood
Copy link
Member

falood commented Jan 30, 2019

@mlankenau
how many endpoints / params have you defined?
and have you tested whether the runtime performance is good?

@mlankenau
Copy link
Author

mlankenau commented Jan 30, 2019

we have around 50 endpoints. Most of them have a small number of params (1-5). Some crud endpoints receive our whole data-structure. We have a macro that is generating the maru params from our ecto schemas. That are around 30 params in the worst case. Our compile time is 120 seconds right now.

@falood
Copy link
Member

falood commented Jan 31, 2019

I have a demo https://gist.github.com/falood/3ecb2f038b6093e081ad7161e5444f44 which take about 8 seconds to compile.
It will be very helpful for me to debug it if you can show me what's your routes struct.

@mlankenau
Copy link
Author

mlankenau commented Feb 1, 2019 via email

@falood
Copy link
Member

falood commented Feb 9, 2019

@mlankenau

how about this issue? can I do any help with this?

@danielkirch
Copy link
Contributor

I am working with @mlankenau on the same project and now I finally had the time to take a closer look at this issue.

The problem seems to come up in combination with the make_plug option. Here is a minimal example with ~200 parameters which takes about 11 seconds to compile on my computer.
(Without make_plug it takes a bit over a second which would be fine.)

api.ex

@falood
Copy link
Member

falood commented Mar 15, 2019

Hi @danielkirch
Thanks for the feedback.
there's only one huge endpoint in your example, can I ask how many endpoints like this in your system?

@danielkirch
Copy link
Contributor

We have one big param structure that we define in a helper module, but we have 5 endpoints that use it. And for each time we use the big param structure it seems to recompile the whole thing because the compile times add up.

(You can check this with the example: put the params into a helper and use it in 2 endpoints, the compile time should be about twice as long as before.)

@falood
Copy link
Member

falood commented Mar 16, 2019

I see, it's expected to take 10 seconds to compile such a complex parameter block, I'll try to decrease the compile time when we include it in several endpoints.

@danielkirch
Copy link
Contributor

Thanks, that would be a great help for us!

I still wonder why the make_plug option makes such a big difference in compile time though. I tried to figure this out by looking at the project myself, but I didn't get very far. Maybe you can give a short explanation for what is happening behind the scenes there?

@danielkirch
Copy link
Contributor

I think I have finally been able to fix this issue (see PR). :D

It seems that the runtime macro generated by the helper was getting a little bloated by repeated quoting and unquoting. In the new version it will first generate the struct and then convert it into a macro. This change cuts down the compile time from about 10 seconds to under 2 seconds.

@falood
Copy link
Member

falood commented May 22, 2019

that's awesome, quote and unquote take a lot of time!
Thanks for figure it out!

@danielkirch
Copy link
Contributor

Sadly, this has become more of an issue again after the changes to the compiler in Elixir 1.8, so we will probably just stick to 1.7 for now. :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants