Skip to content

Commit adaa51f

Browse files
authored
Optimize parser by using nested parser state
When parsing a nested array in chunks efficiently, the parser state (continuation data) needs to be a nested structure. The parser is restructured. It's also faster in other cases. This fixes the issue in the original wooga/eredis: wooga#127
1 parent 40fb5bc commit adaa51f

File tree

3 files changed

+205
-385
lines changed

3 files changed

+205
-385
lines changed

include/eredis.hrl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@
2525
%% Continuation data is whatever data returned by any of the parse
2626
%% functions. This is used to continue where we left off the next time
2727
%% the user calls parse/2.
28-
-type continuation_data() :: any().
29-
-type parser_state() :: status_continue | bulk_continue | multibulk_continue | error_continue.
28+
-type continuation_data() ::
29+
start |
30+
{status_continue, Acc :: binary()} |
31+
{error_continue, Acc :: binary()} |
32+
{bulk_size, Acc :: binary()} |
33+
{multibulk_size, Acc :: binary()} |
34+
{bulk_continue, BytesLeft :: integer(), Acc :: binary()} |
35+
{multibulk_continue, NumLeft :: integer(), Acc :: list()}.
3036

3137
%% Internal types
3238
-ifdef(OTP_RELEASE). % OTP >= 21
@@ -42,8 +48,7 @@
4248
%% Internal parser state. Is returned from parse/2 and must be
4349
%% included on the next calls to parse/2.
4450
-record(pstate, {
45-
state = undefined :: parser_state() | undefined,
46-
continuation_data :: continuation_data() | undefined
51+
states = [] :: [continuation_data()]
4752
}).
4853

4954
-define(NL, "\r\n").

0 commit comments

Comments
 (0)