public
Created

  • Download Gist
shell_test.erl
Erlang
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
LoadQueue = fun(N) ->
lists:foreach(fun(_) ->
self() ! foo
end, lists:seq(1, N))
end.
 
RunTest = fun() ->
lists:foreach(fun(_) ->
Ref = termsend:ref(),
receive Ref -> ok end
end, lists:seq(1, 10000))
end.
 
RunTest(). % This is ~instant
LoadQueue(10000).
RunTest(). % This is ~30-60s
termsend.c
C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include "erl_nif.h"
 
static ERL_NIF_TERM
repeat(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
ErlNifEnv* msg_env = enif_alloc_env();
ERL_NIF_TERM ref = enif_make_ref(env);
ERL_NIF_TERM msg = enif_make_copy(msg_env, ref);
ErlNifPid pid;
 
enif_self(env, &pid);
enif_send(env, &pid, msg_env, msg);
enif_free_env(msg_env);
 
return ref;
}
 
static ErlNifFunc nif_funcs[] = {
{"ref", 0, repeat}
};
 
ERL_NIF_INIT(termsend, nif_funcs, NULL, NULL, NULL, NULL);

I've also tried creating the Ref in Erlang and passing it as an argument to the NIF but it didn't change the behavior.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.