Skip to content

Commit

Permalink
Optimize parser by using nested parser state
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zuiderkwast authored Jun 23, 2021
1 parent 40fb5bc commit adaa51f
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 385 deletions.
13 changes: 9 additions & 4 deletions include/eredis.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@
%% Continuation data is whatever data returned by any of the parse
%% functions. This is used to continue where we left off the next time
%% the user calls parse/2.
-type continuation_data() :: any().
-type parser_state() :: status_continue | bulk_continue | multibulk_continue | error_continue.
-type continuation_data() ::
start |
{status_continue, Acc :: binary()} |
{error_continue, Acc :: binary()} |
{bulk_size, Acc :: binary()} |
{multibulk_size, Acc :: binary()} |
{bulk_continue, BytesLeft :: integer(), Acc :: binary()} |
{multibulk_continue, NumLeft :: integer(), Acc :: list()}.

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

-define(NL, "\r\n").
Expand Down
Loading

0 comments on commit adaa51f

Please sign in to comment.