Force compilation of a single file/files for benchmarking purposes

45 views
Skip to first unread message

Tobias Pfeiffer

unread,
Feb 23, 2023, 4:27:24 AM2/23/23
to elixir-lang-core
Hi everyone and as always, thanks for your amazing work!

Jokes have been lobbied at me in the spirit of the "breaks my worlfow" XKCD [1]  - but, please here me out!

Since the (amazing!) 1.13 [2] elixir semantic recompilation changes I can't easily force recompilation on single files.

The best I know how, is adding empty comments to the files. That is fine for single tries. However, for those who know me, I like benchmarking. Particularly, I'd like to use something like hyperfine [3] to benchmark the compilation. I could write scripts to add/remove comments in between but it seems clumsy.

I might be missing a variant to get this done here.If so, I apologize for not first going to elixirforum.

As for _why_ do I want to do this: I have 3 implementations of the same module. I'd really like to compare the impact of the implementation on compilation time (one generates a bunch of functions to pattern match, the other one just uses a map, there is one variant which also does a file read) to provide general guidance on the impact.

I had hoped that I could do `mix compile --force lib/my_file.ex`, but it always compiles everything. Enabling this interface would be my proposal to remedy this, but y'all might have better ideas or tell me it's not worth it :)

Cheers + thanks,
Tobi

José Valim

unread,
Feb 23, 2023, 5:20:01 AM2/23/23
to elixir-l...@googlegroups.com
Could you potentially use `mix run lib/my_file.ex` for those cases?

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/97956f7b-f789-4b9f-94e3-c3b1bda462d0n%40googlegroups.com.

Wojtek Mach

unread,
Feb 23, 2023, 7:26:59 AM2/23/23
to elixir-l...@googlegroups.com
You can also force recompilation by defining this function:

    def __mix_recompile__?, do: true

Wiadomość napisana przez José Valim <jose....@dashbit.co> w dniu 23.02.2023, o godz. 11:20:



Tobias Pfeiffer

unread,
Feb 23, 2023, 8:12:01 AM2/23/23
to elixir-lang-core
Interesting! I always forget elixir modules are also "just" evaluated until I don't. `mix run --no-start` does indeed seem to work for this use case!

Thank you!

Tobias Pfeiffer

unread,
Feb 23, 2023, 11:39:12 AM2/23/23
to elixir-lang-core

Thanks, I know :) The problem with that is wanting to run a benchmark with all examples in it, so this would always force compilation for all 3 files which doesn't help with that particular benchmarking case.
Reply all
Reply to author
Forward
0 new messages