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

Incremental compilation for Mix.install/2 #13756

Conversation

tywhisky
Copy link
Contributor

@tywhisky tywhisky commented Aug 3, 2024

#12293
I see that file copying has been implemented in previous PRs. So if I'm not misunderstanding the requirements. I think the issue is how to locate to the previous version.

My solution:

  1. Separate install_project_dir to encode the generated path.
  2. Then use String.starts_with? to find the most recently modified version.
  3. Execute the restore logic.

Users can still specify the restore directory by manually exporting the environment variable.

Comment on lines +1048 to +1056
entries
|> Enum.filter(&String.starts_with?(&1, id_without_deps))
|> Enum.map(&Path.join(version_dir, &1))
|> Enum.map(&{&1, File.stat!(&1).mtime})
|> Enum.max_by(&elem(&1, 1), fn -> nil end)
|> case do
{latest_dir, _mtime} -> latest_dir
nil -> nil
end
Copy link
Contributor

@dkuku dkuku Aug 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like this would be easier to read?
I lost track on 1052, I'm just guessing what should be the result.

Suggested change
entries
|> Enum.filter(&String.starts_with?(&1, id_without_deps))
|> Enum.map(&Path.join(version_dir, &1))
|> Enum.map(&{&1, File.stat!(&1).mtime})
|> Enum.max_by(&elem(&1, 1), fn -> nil end)
|> case do
{latest_dir, _mtime} -> latest_dir
nil -> nil
end
for entry <- entries,
String.starts_with?(entry, id_without_deps),
current_path = Path.join(version_dir, entry),
%{mtime: current_mtime} = File.stat!(current_path),
reduce: {nil, nil} do
{nil, nil} -> {current_path, current_mtime}
{_path, mtime} when current_mtime > mtime -> {current_path, current_mtime}
acc -> acc
end
|> elem(0)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH for me, I like pipe operator more, but thank you for advice.

@josevalim
Copy link
Member

Hi @tywhisky, thank you for the PR, but the actual implementation is much more complex than that (to the point we are not sure it is worth it given the complexity).

The issue is that we want to allow multiple Mix.install to be called within the same instance. This means that, between every Mix.install, we need to compute both dependency graphs, figure out which deps were added/updated/removed, purge the applications and all of their code.

The issue is not to locate the previous version, sorry for any confusion. :(

@tywhisky
Copy link
Contributor Author

tywhisky commented Aug 3, 2024

@josevalim That's fine, there's always a lot to learn from reading the source code, I just hope I didn't add to the trouble😂, and I actually did consider the meaning of instance along the way, I'll be more prepared next time.

@tywhisky tywhisky closed this Aug 3, 2024
@josevalim
Copy link
Member

No worries! If you learned something, then it was worth it. Hopefully we will merge the next one!

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

Successfully merging this pull request may close these issues.

3 participants