Skip to content

@davisp /shell_test.erl
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
#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);
@davisp
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.