mnesia_frag_hash key_to_frag_number optimisation(?)

Philip Robinson chlorophil@REDACTED
Mon Mar 21 03:38:10 CET 2011


I was poking around in mnesia_frag_hash.erl and noticed that it might
be possible to reduce the number of calls to phash by tweaking
key_to_frag_number/2 a little bit.

I have attached a test file that I used to see if my changes break
anything, and a diff for mnesia_frag_hash.erl itself.

Everything looks fine to me, but I am not an mnesia guru by any
stretch of the imagination. Does this change seem reasonable?

Thanks,
Philip
-------------- next part --------------
104,106c104,106
< key_to_frag_number(#hash_state{function = phash, next_n_to_split = SplitN, n_doubles = L}, Key) ->
<     P = SplitN,
<     A = erlang:phash(Key, power2(L)),
---
> key_to_frag_number(#hash_state{function = phash, next_n_to_split = P, n_doubles = L}, Key) ->
>     D = power2(L + 1),
>     A = erlang:phash(Key, D),
108,111c108,111
< 	A < P ->
< 	    erlang:phash(Key, power2(L + 1));
< 	true ->
< 	    A
---
>         A >= (D + P) ->
>             A - D;
>         true ->
>             A
113,115c113,115
< key_to_frag_number(#hash_state{function = phash2, next_n_to_split = SplitN, n_doubles = L}, Key) ->
<     P = SplitN,
<     A = erlang:phash2(Key, power2(L)) + 1,
---
> key_to_frag_number(#hash_state{function = phash2, next_n_to_split = P, n_doubles = L}, Key) ->
>     D = power2(L + 1),
>     A = erlang:phash2(Key, D) + 1,
117,120c117,120
< 	A < P ->
< 	    erlang:phash2(Key, power2(L + 1)) + 1;
< 	true ->
< 	    A
---
>         A >= (D + P) ->
>             A - D;
>         true ->
>             A
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mnesia_frag_hash_test.erl
Type: application/octet-stream
Size: 1723 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20110321/e4341f10/attachment.obj>


More information about the erlang-patches mailing list