Skip to content

Commit a88eb05

Browse files
committed
Trim the request hot path
buoy_pool:lookup pays an extra dispatch through foil_modules on every request; calling the foil-generated module directly halves the lookup cost. buoy_client:handle_data avoids rebuilding the binary when the parse buffer is empty.
1 parent ff81ff7 commit a88eb05

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/buoy_client.erl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ handle_data(Data, #state {
6565
response = Response
6666
} = State) ->
6767

68-
Data2 = <<Buffer/binary, Data/binary>>,
68+
Data2 = case Buffer of
69+
<<>> ->
70+
Data;
71+
_ ->
72+
<<Buffer/binary, Data/binary>>
73+
end,
6974
case responses(Data2, Queue, Response, BinPatterns, []) of
7075
{ok, Queue2, Response2, Responses, Rest} ->
7176
{ok, Responses, State#state {

src/buoy_pool.erl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
-module(buoy_pool).
22
-include("buoy_internal.hrl").
33

4+
-dialyzer({nowarn_function, lookup/3}).
5+
-ignore_xref([
6+
{buoy_pool_foil, lookup, 1}
7+
]).
8+
49
-export([
510
init/0,
611
lookup/3,
@@ -21,13 +26,16 @@ init() ->
2126
-spec lookup(protocol_http(), hostname(), inet:port_number()) ->
2227
{ok, atom()} | {error, pool_not_started | buoy_not_started}.
2328

29+
%% calls the foil-generated module directly: foil:lookup pays an
30+
%% extra dispatch through foil_modules on every request
2431
lookup(Protocol, Hostname, Port) ->
25-
case foil:lookup(buoy_pool, {Protocol, Hostname, Port}) of
32+
try buoy_pool_foil:lookup({Protocol, Hostname, Port}) of
2633
{ok, _} = R ->
2734
R;
2835
{error, key_not_found} ->
29-
{error, pool_not_started};
30-
{error, _} ->
36+
{error, pool_not_started}
37+
catch
38+
error:undef ->
3139
{error, buoy_not_started}
3240
end.
3341

0 commit comments

Comments
 (0)