• Martin Möhrmann's avatar
    strings: speed up FieldsFunc · fee7f2ab
    Martin Möhrmann authored
    Increases performance of FieldsFunc by recording the start and end
    of the fields in an array. The first 32 fields are saved in a pre-allocated
    array on the stack. This avoids the old behavior of iterating over the
    input string two times but uses more allocations when more than 32 fields
    are encountered.
    
    Additionally code for handling non-ASCII containing strings from Fields is
    removed and replaced by a call to the new faster FieldsFunc function.
    
    Overall this still leads to a slowdown for Fields on non-ASCII strings
    while speeding up Fields in general.
    
    name                      old time/op    new time/op     delta
    Fields/ASCII/16              116ns ± 5%      115ns ± 5%       ~     (p=0.480 n=10+10)
    Fields/ASCII/256             765ns ± 1%      761ns ± 2%       ~     (p=0.171 n=10+10)
    Fields/ASCII/4096           12.5µs ± 1%     12.7µs ± 1%     +1.82%  (p=0.000 n=10+10)
    Fields/ASCII/65536           226µs ± 1%      226µs ± 2%       ~     (p=0.739 n=10+10)
    Fields/ASCII/1048576        5.12ms ± 1%     5.12ms ± 1%       ~     (p=0.696 n=8+10)
    Fields/Mixed/16              172ns ± 1%      233ns ± 1%    +35.90%  (p=0.000 n=9+10)
    Fields/Mixed/256            1.18µs ± 2%     2.45µs ± 1%   +107.47%  (p=0.000 n=10+10)
    Fields/Mixed/4096           20.3µs ± 1%     43.1µs ± 2%   +112.41%  (p=0.000 n=10+10)
    Fields/Mixed/65536           364µs ± 1%      704µs ± 1%    +93.56%  (p=0.000 n=9+10)
    Fields/Mixed/1048576        7.07ms ± 2%    13.34ms ± 4%    +88.83%  (p=0.000 n=10+10)
    FieldsFunc/ASCII/16          274ns ± 1%      188ns ± 3%    -31.44%  (p=0.000 n=10+10)
    FieldsFunc/ASCII/256        3.69µs ± 1%     2.06µs ± 2%    -44.26%  (p=0.000 n=10+10)
    FieldsFunc/ASCII/4096       59.9µs ± 1%     35.3µs ± 2%    -41.10%  (p=0.000 n=10+10)
    FieldsFunc/ASCII/65536       958µs ± 1%      567µs ± 1%    -40.82%  (p=0.000 n=10+9)
    FieldsFunc/ASCII/1048576    16.3ms ± 2%     11.0ms ± 3%    -32.52%  (p=0.000 n=10+10)
    FieldsFunc/Mixed/16          309ns ± 1%      213ns ± 0%    -30.98%  (p=0.000 n=10+6)
    FieldsFunc/Mixed/256        3.83µs ± 1%     2.14µs ± 1%    -44.01%  (p=0.000 n=10+10)
    FieldsFunc/Mixed/4096       66.2µs ± 2%     37.8µs ± 1%    -42.85%  (p=0.000 n=10+10)
    FieldsFunc/Mixed/65536      1.09ms ± 1%     0.63ms ± 1%    -42.73%  (p=0.000 n=10+10)
    FieldsFunc/Mixed/1048576    18.6ms ± 3%     12.0ms ± 2%    -35.50%  (p=0.000 n=10+10)
    
    Fixes #17856
    Fixes #19789
    
    Change-Id: I9f5a560e534566fd81963651f342c8f44cfb0469
    Reviewed-on: https://go-review.googlesource.com/42810Reviewed-by: 's avatarJoe Tsai <thebrokentoaster@gmail.com>
    fee7f2ab
Name
Last commit
Last update
..
compare.go Loading commit data...
compare_test.go Loading commit data...
example_test.go Loading commit data...
export_test.go Loading commit data...
reader.go Loading commit data...
reader_test.go Loading commit data...
replace.go Loading commit data...
replace_test.go Loading commit data...
search.go Loading commit data...
search_test.go Loading commit data...
strings.go Loading commit data...
strings.s Loading commit data...
strings_amd64.go Loading commit data...
strings_decl.go Loading commit data...
strings_generic.go Loading commit data...
strings_s390x.go Loading commit data...
strings_test.go Loading commit data...