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

Commit

Permalink
Start using memoization server
Browse files Browse the repository at this point in the history
1. memoize otp release vsn string function call

2. memoize expensive filename:absname/1 call which happens
   to be called quite frequently
  • Loading branch information
Tuncer Ayaz committed Jun 12, 2015
1 parent 02c4300 commit ec018cf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
6 changes: 6 additions & 0 deletions src/rebar.erl
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ run_aux(BaseConfig, Commands) ->
{error,{already_started,crypto}} -> ok
end,

%% Make sure memoization server is running
case rmemo:start() of
{ok, _} -> ok;
{error, {already_started, _}} -> ok
end,

%% Convert command strings to atoms
CommandAtoms = [list_to_atom(C) || C <- Commands],

Expand Down
25 changes: 6 additions & 19 deletions src/rebar_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,11 @@ prop_check(false, Msg, Args) -> ?ABORT(Msg, Args).

%% Convert all the entries in the code path to absolute paths.
expand_code_path() ->
CodePath = lists:foldl(fun(Path, Acc) ->
[filename:absname(Path) | Acc]
end, [], code:get_path()),
CodePath = lists:foldl(
fun(Path, Acc) ->
Path1 = rmemo:call(filename, absname, [Path]),
[Path1 | Acc]
end, [], code:get_path()),
code:set_path(lists:reverse(CodePath)).

%%
Expand Down Expand Up @@ -403,22 +405,7 @@ patch_env(Config, [E | Rest]) ->
%% ====================================================================

otp_release() ->
%% NOTE: All and any pdict use has been erased from rebar a long
%% time ago in a big refactoring, and while extra processes (think
%% base_compiler) may have to re-cache the vsn string, this is
%% tolerable as an exception. After all, it's a write-once value.
%%
%% We cache the return of otp_release1, since otherwise, we're
%% repeatedly reading the same file off the hard drive and
%% generating warnings if they aren't there.
case erlang:get(otp_release_cache) of
undefined ->
Vsn = otp_release1(erlang:system_info(otp_release)),
erlang:put(otp_release_cache, Vsn),
Vsn;
Vsn ->
Vsn
end.
rmemo:call(fun otp_release1/1, [(erlang:system_info(otp_release))]).

%% If OTP <= R16, otp_release is already what we want.
otp_release1([$R,N|_]=Rel) when is_integer(N) ->
Expand Down

0 comments on commit ec018cf

Please sign in to comment.