Skip to content
This repository has been archived by the owner on May 12, 2018. It is now read-only.

Manually clean up paths. #344

Merged
merged 1 commit into from Aug 18, 2014
Merged

Conversation

evanmcc
Copy link
Contributor

@evanmcc evanmcc commented Aug 16, 2014

Using code:set_path/1 with very large paths is very slow on larger
projects. On my mid-sized project, it seems to take around .4s per
call. Emulating the call with direct path removal (using
code:del_path/1) seems to be quite a lot faster.

@Vagabond
Copy link
Contributor

This seems to shave about 30% off the time for a riak build. I've reviewed the code and tested it and I'm +1 on this change.

@Vagabond
Copy link
Contributor

30% off the time for a build when everythng is already built, I should clarity.

@seth
Copy link

seth commented Aug 16, 2014

set_path does verification of the paths and read file data. e.g. here: https://github.com/erlang/otp/blob/maint/lib/kernel/src/code_server.erl#L777

so makes sense that manual cleanup via del_path is faster.

@@ -603,3 +604,17 @@ filter_defines([{platform_define, ArchRegex, Key, Value} | Rest], Acc) ->
end;
filter_defines([Opt | Rest], Acc) ->
filter_defines(Rest, [Opt | Acc]).

cleanup_path(OrigPath) ->
Copy link

Choose a reason for hiding this comment

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

How about renaming the fun to cleanup_code_path/1, as this module is a collection of many unrelated funs?

@ghost
Copy link

ghost commented Aug 16, 2014

Thanks @evanmcc. We don't (yet) have a test suite for code path changes, but the updated CONTRIBUTING guide requires tests for behavioral changes. So, we should try to write tests before we merge this.

@ghost
Copy link

ghost commented Aug 16, 2014

Minor commit message issue: following CONTRIBUTING#commit-titlesummary, there should be no period in the title/summary.

@evanmcc
Copy link
Contributor Author

evanmcc commented Aug 16, 2014

I've addressed all of the concerns but adding the test. If someone sees an easy way to test this, I'm all ears. Otherwise I'll try to figure it out on Monday.

@ghost
Copy link

ghost commented Aug 16, 2014

Thanks.

cleanup_code_path(OrigPath) ->
CurrentPath = code:get_path(),
AddedPaths = CurrentPath -- OrigPath,
%% if someone has removed paths, it's hard to get them back into
Copy link

Choose a reason for hiding this comment

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

Minor typo: if someone -> If someone

@ferd
Copy link
Contributor

ferd commented Aug 18, 2014

Looking at the operations in code:add_path, this sounds relatively safe. If I get it right, set_path will manually re-scan all the paths in the list to make sure to extract .ez archives and whatnot, whereas delete_path checks nothing and add_path only checks the new path.

This sounds safe enough to me for a decent performance gain.

@ferd
Copy link
Contributor

ferd commented Aug 18, 2014

Sorry, I noticed that we never re-add paths. In the off-chance some paths were deleted somewhere in the code we set_path again with this patch. It seems slower than trying to re-add the missing ones one by one and hoping they also fall in the same order, but safer. I'm fine with it.

@evanmcc
Copy link
Contributor Author

evanmcc commented Aug 18, 2014

Can I get some clarification on what needs to happen to get this mergeable? A test and ??

@ferd
Copy link
Contributor

ferd commented Aug 18, 2014

I'm guessing tests and fixing the typo @Tuncer has seen in a comment. The rest seemed good to me, unless someone has something else to point out.

@Vagabond
Copy link
Contributor

What would a test even look like, I don't even know why rebar resets paths like this, is it in case a task changes the paths somehow? Presumably via some plugin?

@evanmcc
Copy link
Contributor Author

evanmcc commented Aug 18, 2014

My plan was just to manually add and remove some paths and then test that they get properly reset. I have no idea how to test it as it would actually be used in rebar.

@ferd
Copy link
Contributor

ferd commented Aug 18, 2014

I would probably be fine testing the path changes done with code:set_path and the new method and making sure that they're equivalent.

@evanmcc
Copy link
Contributor Author

evanmcc commented Aug 18, 2014

Typo fixed, tests added, LC return explicitly ignored.

@Vagabond
Copy link
Contributor

The eunit tests are calling teardown without setting the path and teardown() calls set_cwd(".."), which is silly but hard to fix right now.

Here's a patch to make the tests green:

 code_path_test_() ->
     [{"Ensuring that fast code path cleanup is correct for adds",
-     setup, fun make_tmp_dir/0, fun teardown/1,
+     setup, fun make_tmp_dir/0,
+      fun(_) -> remove_tmp_dir() end,
      fun() ->
              OPath = code:get_path(),
              PathZ = ?TMP_DIR ++ "some_path",

Using code:set_path/1 with very large paths is very slow on larger
projects.  On my mid-sized project, it seems to take around .4s per
call.  Emulating the call with direct path removal (using
code:del_path/1) seems to be quite a lot faster.
@Vagabond
Copy link
Contributor

Merging this.

Vagabond added a commit that referenced this pull request Aug 18, 2014
@Vagabond Vagabond merged commit a467abb into rebar:master Aug 18, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants