Commit dd6090e
committed
speed up string decoding
This speeds up string decoding by using `rb_str_substr` rather than
`rb_str_new`. `rb_str_substr` will create shared strings, so it will
avoid string copying like `rb_str_new` will do.
Before this patch:
```
[aaron@TC bert (master)]$ ruby -I lib:test bench/decode_bench.rb
user system total real
BERT C Extension Decoder
BERT tiny 0.000000 0.000000 0.000000 ( 0.000574)
BERT small 0.010000 0.010000 0.020000 ( 0.014938)
BERT large 13.990000 11.640000 25.630000 ( 25.892584)
BERT complex 0.030000 0.010000 0.040000 ( 0.033596)
```
After this patch:
```
[aaron@TC bert (master)]$ ruby -I lib:test bench/decode_bench.rb
user system total real
BERT C Extension Decoder
BERT tiny 0.000000 0.000000 0.000000 ( 0.000563)
BERT small 0.010000 0.000000 0.010000 ( 0.008701)
BERT large 6.180000 0.040000 6.220000 ( 6.299307)
BERT complex 0.060000 0.000000 0.060000 ( 0.070287)
```1 parent 7ce2909 commit dd6090e
1 file changed
+5
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
300 | 302 | | |
301 | 303 | | |
302 | 304 | | |
303 | | - | |
| 305 | + | |
304 | 306 | | |
305 | 307 | | |
306 | 308 | | |
| |||
512 | 514 | | |
513 | 515 | | |
514 | 516 | | |
| 517 | + | |
| 518 | + | |
515 | 519 | | |
516 | 520 | | |
517 | 521 | | |
| |||
0 commit comments