Skip to content

Commit f066167

Browse files
byroottenderlove
andcommitted
Resp3#parse use a jump table rather than a hash lookup + send
THe main gain is to have proper method calls rather than dynamic `send`. Co-authored-by: Aaron Patterson <[email protected]>
1 parent 9fabd57 commit f066167

File tree

4 files changed

+54
-26
lines changed

4 files changed

+54
-26
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ Lint/UnderscorePrefixedVariableName:
3636
Lint/EmptyBlock:
3737
Enabled: false
3838

39+
Lint/DuplicateBranch:
40+
Enabled: false
41+
3942
Lint/MissingSuper:
4043
Enabled: false
4144

benchmark/drivers_ruby.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,53 @@ redis-server: `Redis server v=7.0.12 sha=00000000:0 malloc=libc bits=64 build=a1
77

88
```
99
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
10-
hiredis: 5402.4 i/s
11-
ruby: 2877.9 i/s - 1.88x slower
10+
hiredis: 5416.0 i/s
11+
ruby: 2923.7 i/s - 1.85x slower
1212
1313
```
1414

1515
### large string x 100
1616

1717
```
1818
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
19-
hiredis: 297.2 i/s
20-
ruby: 291.2 i/s - same-ish: difference falls within error
19+
hiredis: 286.7 i/s
20+
ruby: 302.3 i/s - same-ish: difference falls within error
2121
2222
```
2323

2424
### small list x 100
2525

2626
```
2727
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
28-
hiredis: 2632.0 i/s
29-
ruby: 1136.1 i/s - 2.32x slower
28+
hiredis: 2596.0 i/s
29+
ruby: 1155.6 i/s - 2.25x slower
3030
3131
```
3232

3333
### large list
3434

3535
```
3636
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
37-
hiredis: 6640.8 i/s
38-
ruby: 1293.1 i/s - 5.14x slower
37+
hiredis: 6797.0 i/s
38+
ruby: 1388.9 i/s - 4.89x slower
3939
4040
```
4141

4242
### small hash x 100
4343

4444
```
4545
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
46-
hiredis: 3419.6 i/s
47-
ruby: 1129.0 i/s - 3.03x slower
46+
hiredis: 3459.8 i/s
47+
ruby: 1170.4 i/s - 2.96x slower
4848
4949
```
5050

5151
### large hash
5252

5353
```
5454
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
55-
hiredis: 1299.3 i/s
56-
ruby: 1275.3 i/s - same-ish: difference falls within error
55+
hiredis: 1345.9 i/s
56+
ruby: 1329.5 i/s - same-ish: difference falls within error
5757
5858
```
5959

benchmark/drivers_yjit.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,53 @@ redis-server: `Redis server v=7.0.12 sha=00000000:0 malloc=libc bits=64 build=a1
77

88
```
99
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +YJIT [arm64-darwin23]
10-
hiredis: 6745.7 i/s
11-
ruby: 5182.0 i/s - 1.30x slower
10+
hiredis: 6775.6 i/s
11+
ruby: 5212.3 i/s - 1.30x slower
1212
1313
```
1414

1515
### large string x 100
1616

1717
```
1818
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +YJIT [arm64-darwin23]
19-
hiredis: 303.5 i/s
20-
ruby: 343.1 i/s - 1.13x faster
19+
hiredis: 306.1 i/s
20+
ruby: 335.5 i/s - same-ish: difference falls within error
2121
2222
```
2323

2424
### small list x 100
2525

2626
```
2727
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +YJIT [arm64-darwin23]
28-
hiredis: 3683.6 i/s
29-
ruby: 1952.3 i/s - 1.89x slower
28+
hiredis: 3566.7 i/s
29+
ruby: 1999.6 i/s - 1.78x slower
3030
3131
```
3232

3333
### large list
3434

3535
```
3636
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +YJIT [arm64-darwin23]
37-
hiredis: 6540.2 i/s
38-
ruby: 2710.0 i/s - 2.41x slower
37+
hiredis: 6563.1 i/s
38+
ruby: 2984.7 i/s - 2.20x slower
3939
4040
```
4141

4242
### small hash x 100
4343

4444
```
4545
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +YJIT [arm64-darwin23]
46-
hiredis: 4002.6 i/s
47-
ruby: 2317.0 i/s - 1.73x slower
46+
hiredis: 3870.9 i/s
47+
ruby: 2387.4 i/s - 1.62x slower
4848
4949
```
5050

5151
### large hash
5252

5353
```
5454
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +YJIT [arm64-darwin23]
55-
hiredis: 2467.1 i/s
56-
ruby: 2439.0 i/s - same-ish: difference falls within error
55+
hiredis: 2641.9 i/s
56+
ruby: 2575.8 i/s - same-ish: difference falls within error
5757
5858
```
5959

lib/redis_client/ruby_connection/resp3.rb

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,35 @@ def dump_symbol(symbol, buffer)
111111

112112
def parse(io)
113113
type = io.getbyte
114-
method = PARSER_TYPES.fetch(type) do
114+
if type == 35 # '#'.ord
115+
parse_boolean(io)
116+
elsif type == 36 # '$'.ord
117+
parse_blob(io)
118+
elsif type == 43 # '+'.ord
119+
parse_string(io)
120+
elsif type == 61 # '='.ord
121+
parse_verbatim_string(io)
122+
elsif type == 45 # '-'.ord
123+
parse_error(io)
124+
elsif type == 58 # ':'.ord
125+
parse_integer(io)
126+
elsif type == 40 # '('.ord
127+
parse_integer(io)
128+
elsif type == 44 # ','.ord
129+
parse_double(io)
130+
elsif type == 95 # '_'.ord
131+
parse_null(io)
132+
elsif type == 42 # '*'.ord
133+
parse_array(io)
134+
elsif type == 37 # '%'.ord
135+
parse_map(io)
136+
elsif type == 126 # '~'.ord
137+
parse_set(io)
138+
elsif type == 62 # '>'.ord
139+
parse_array(io)
140+
else
115141
raise UnknownType, "Unknown sigil type: #{type.chr.inspect}"
116142
end
117-
send(method, io)
118143
end
119144

120145
def parse_string(io)

0 commit comments

Comments
 (0)