diff options
author | Magnus Henoch <[email protected]> | 2014-06-27 17:57:04 +0100 |
---|---|---|
committer | Magnus Henoch <[email protected]> | 2014-09-19 18:48:12 +0100 |
commit | 69e8387629bdea141e196c515f4d9381f7ac3e18 (patch) | |
tree | fb9843a0e7828942c289df7a689b64238c7f8338 /lib/stdlib/src/io.erl | |
parent | 6ec976bd70a657efea2d5d714e0d470aeb86bb50 (diff) | |
download | otp-69e8387629bdea141e196c515f4d9381f7ac3e18.tar.gz otp-69e8387629bdea141e196c515f4d9381f7ac3e18.tar.bz2 otp-69e8387629bdea141e196c515f4d9381f7ac3e18.zip |
Optimise io requests for long message queues
Ensure that the monitor reference is present in all receive clauses, so
that the compiler optimisation kicks in and the run time won't depend on
the length of the message queue of the calling process.
Remove the 'EXIT' clause, as its presence breaks the optimisation, and
that case is handled by the 'DOWN' clause anyway.
The test io_SUITE:io_with_huge_message_queue is an adaptation of
gen_server_SUITE:call_with_huge_message_queue.
Diffstat (limited to 'lib/stdlib/src/io.erl')
-rw-r--r-- | lib/stdlib/src/io.erl | 43 |
1 files changed, 17 insertions, 26 deletions
diff --git a/lib/stdlib/src/io.erl b/lib/stdlib/src/io.erl index 27e2a82b41..b9ace2f442 100644 --- a/lib/stdlib/src/io.erl +++ b/lib/stdlib/src/io.erl @@ -566,12 +566,23 @@ request(Name, Request) when is_atom(Name) -> execute_request(Pid, {Convert,Converted}) -> Mref = erlang:monitor(process, Pid), - Pid ! {io_request,self(),Pid,Converted}, - if - Convert -> - convert_binaries(wait_io_mon_reply(Pid, Mref)); - true -> - wait_io_mon_reply(Pid, Mref) + Pid ! {io_request,self(),Mref,Converted}, + + receive + {io_reply, Mref, Reply} -> + erlang:demonitor(Mref, [flush]), + if + Convert -> + convert_binaries(Reply); + true -> + Reply + end; + {'DOWN', Mref, _, _, _} -> + receive + {'EXIT', Pid, _What} -> true + after 0 -> true + end, + {error,terminated} end. requests(Requests) -> %Requests as atomic action @@ -597,26 +608,6 @@ default_input() -> default_output() -> group_leader(). -wait_io_mon_reply(From, Mref) -> - receive - {io_reply, From, Reply} -> - erlang:demonitor(Mref, [flush]), - Reply; - {'EXIT', From, _What} -> - receive - {'DOWN', Mref, _, _, _} -> true - after 0 -> true - end, - {error,terminated}; - {'DOWN', Mref, _, _, _} -> - receive - {'EXIT', From, _What} -> true - after 0 -> true - end, - {error,terminated} - end. - - %% io_requests(Requests) %% Transform requests into correct i/o server messages. Only handle the %% one we KNOW must be changed, others, including incorrect ones, are |