Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoder: use lookup table to validate ASCII #654

Merged
merged 1 commit into from Nov 4, 2021
Merged

Decoder: use lookup table to validate ASCII #654

merged 1 commit into from Nov 4, 2021

Conversation

pelletier
Copy link
Owner

@pelletier pelletier commented Nov 4, 2021

Trade-off: adds 256 bytes to the resulting binary. Go 1.17 stores the table in rodata and inline the call:

        0x0025 00037 (utf8.go:181)      LEAQ    "".invalidAsciiTable(SB), CX
        0x002c 00044 (utf8.go:181)      MOVBLZX (CX)(DX*1), CX
        0x0030 00048 (utf8.go:181)      TESTB   CL, CL

Benchmark results

(allocations omitted as they are unchanged)

name                        old time/op    new time/op    delta
ParseBasicStringsEasy/1-2     10.6ns ± 0%    10.3ns ± 0%   -2.90%  (p=0.016 n=4+5)
ParseBasicStringsEasy/4-2     16.0ns ± 0%    14.8ns ± 0%   -7.31%  (p=0.008 n=5+5)
ParseBasicStringsEasy/8-2     23.8ns ± 1%    21.0ns ± 1%  -11.94%  (p=0.008 n=5+5)
ParseBasicStringsEasy/16-2    36.0ns ± 1%    32.0ns ± 3%  -11.04%  (p=0.008 n=5+5)
ParseBasicStringsEasy/21-2    44.9ns ± 1%    40.3ns ± 0%  -10.24%  (p=0.016 n=5+4)

name                        old speed      new speed      delta
ParseBasicStringsEasy/1-2    282MB/s ± 0%   290MB/s ± 0%   +2.98%  (p=0.016 n=4+5)
ParseBasicStringsEasy/4-2    375MB/s ± 0%   405MB/s ± 0%   +7.89%  (p=0.008 n=5+5)
ParseBasicStringsEasy/8-2    420MB/s ± 1%   476MB/s ± 1%  +13.53%  (p=0.008 n=5+5)
ParseBasicStringsEasy/16-2   500MB/s ± 1%   562MB/s ± 3%  +12.47%  (p=0.008 n=5+5)
ParseBasicStringsEasy/21-2   512MB/s ± 1%   573MB/s ± 2%  +11.81%  (p=0.008 n=5+5)

name                               old time/op    new time/op    delta
UnmarshalDataset/config-2            24.7ms ± 0%    24.5ms ± 0%  -1.04%  (p=0.008 n=5+5)
UnmarshalDataset/canada-2            84.6ms ± 0%    85.1ms ± 2%    ~     (p=0.413 n=4+5)
UnmarshalDataset/citm_catalog-2      25.8ms ± 2%    25.7ms ± 1%    ~     (p=1.000 n=5+5)
UnmarshalDataset/twitter-2           9.53ms ± 0%    9.38ms ± 0%  -1.51%  (p=0.008 n=5+5)
UnmarshalDataset/code-2               107ms ± 1%     107ms ± 1%    ~     (p=0.222 n=5+5)
UnmarshalDataset/example-2            165µs ± 2%     163µs ± 0%  -1.06%  (p=0.016 n=5+4)
Unmarshal/SimpleDocument/struct-2     574ns ± 1%     570ns ± 1%    ~     (p=0.056 n=5+5)
Unmarshal/SimpleDocument/map-2        848ns ± 1%     845ns ± 0%    ~     (p=0.310 n=5+5)
Unmarshal/ReferenceFile/struct-2     55.8µs ± 0%    54.0µs ± 0%  -3.24%  (p=0.008 n=5+5)
Unmarshal/ReferenceFile/map-2        83.5µs ± 2%    81.0µs ± 0%  -2.98%  (p=0.008 n=5+5)
Unmarshal/HugoFrontMatter-2          14.4µs ± 1%    14.2µs ± 0%  -1.48%  (p=0.008 n=5+5)

name                               old speed      new speed      delta
UnmarshalDataset/config-2          42.4MB/s ± 0%  42.9MB/s ± 0%  +1.05%  (p=0.008 n=5+5)
UnmarshalDataset/canada-2          26.0MB/s ± 0%  25.9MB/s ± 1%    ~     (p=0.460 n=4+5)
UnmarshalDataset/citm_catalog-2    21.6MB/s ± 2%  21.7MB/s ± 1%    ~     (p=0.952 n=5+5)
UnmarshalDataset/twitter-2         46.4MB/s ± 0%  47.1MB/s ± 0%  +1.53%  (p=0.008 n=5+5)
UnmarshalDataset/code-2            25.0MB/s ± 1%  25.1MB/s ± 1%    ~     (p=0.175 n=5+5)
UnmarshalDataset/example-2         49.2MB/s ± 2%  49.7MB/s ± 0%  +1.07%  (p=0.016 n=5+4)
Unmarshal/SimpleDocument/struct-2  19.2MB/s ± 1%  19.3MB/s ± 0%  +0.74%  (p=0.048 n=5+5)
Unmarshal/SimpleDocument/map-2     13.0MB/s ± 1%  13.0MB/s ± 0%    ~     (p=0.254 n=5+5)
Unmarshal/ReferenceFile/struct-2   94.0MB/s ± 0%  97.1MB/s ± 0%  +3.35%  (p=0.008 n=5+5)
Unmarshal/ReferenceFile/map-2      62.8MB/s ± 2%  64.7MB/s ± 0%  +3.06%  (p=0.008 n=5+5)
Unmarshal/HugoFrontMatter-2        37.9MB/s ± 1%  38.4MB/s ± 0%  +1.49%  (p=0.008 n=5+5)

```
name                        old time/op    new time/op    delta
ParseBasicStringsEasy/1-2     10.6ns ± 0%    10.3ns ± 0%   -2.90%  (p=0.016 n=4+5)
ParseBasicStringsEasy/4-2     16.0ns ± 0%    14.8ns ± 0%   -7.31%  (p=0.008 n=5+5)
ParseBasicStringsEasy/8-2     23.8ns ± 1%    21.0ns ± 1%  -11.94%  (p=0.008 n=5+5)
ParseBasicStringsEasy/16-2    36.0ns ± 1%    32.0ns ± 3%  -11.04%  (p=0.008 n=5+5)
ParseBasicStringsEasy/21-2    44.9ns ± 1%    40.3ns ± 0%  -10.24%  (p=0.016 n=5+4)

name                        old speed      new speed      delta
ParseBasicStringsEasy/1-2    282MB/s ± 0%   290MB/s ± 0%   +2.98%  (p=0.016 n=4+5)
ParseBasicStringsEasy/4-2    375MB/s ± 0%   405MB/s ± 0%   +7.89%  (p=0.008 n=5+5)
ParseBasicStringsEasy/8-2    420MB/s ± 1%   476MB/s ± 1%  +13.53%  (p=0.008 n=5+5)
ParseBasicStringsEasy/16-2   500MB/s ± 1%   562MB/s ± 3%  +12.47%  (p=0.008 n=5+5)
ParseBasicStringsEasy/21-2   512MB/s ± 1%   573MB/s ± 2%  +11.81%  (p=0.008 n=5+5)

name                               old time/op    new time/op    delta
UnmarshalDataset/config-2            24.7ms ± 0%    24.5ms ± 0%  -1.04%  (p=0.008 n=5+5)
UnmarshalDataset/canada-2            84.6ms ± 0%    85.1ms ± 2%    ~     (p=0.413 n=4+5)
UnmarshalDataset/citm_catalog-2      25.8ms ± 2%    25.7ms ± 1%    ~     (p=1.000 n=5+5)
UnmarshalDataset/twitter-2           9.53ms ± 0%    9.38ms ± 0%  -1.51%  (p=0.008 n=5+5)
UnmarshalDataset/code-2               107ms ± 1%     107ms ± 1%    ~     (p=0.222 n=5+5)
UnmarshalDataset/example-2            165µs ± 2%     163µs ± 0%  -1.06%  (p=0.016 n=5+4)
Unmarshal/SimpleDocument/struct-2     574ns ± 1%     570ns ± 1%    ~     (p=0.056 n=5+5)
Unmarshal/SimpleDocument/map-2        848ns ± 1%     845ns ± 0%    ~     (p=0.310 n=5+5)
Unmarshal/ReferenceFile/struct-2     55.8µs ± 0%    54.0µs ± 0%  -3.24%  (p=0.008 n=5+5)
Unmarshal/ReferenceFile/map-2        83.5µs ± 2%    81.0µs ± 0%  -2.98%  (p=0.008 n=5+5)
Unmarshal/HugoFrontMatter-2          14.4µs ± 1%    14.2µs ± 0%  -1.48%  (p=0.008 n=5+5)

name                               old speed      new speed      delta
UnmarshalDataset/config-2          42.4MB/s ± 0%  42.9MB/s ± 0%  +1.05%  (p=0.008 n=5+5)
UnmarshalDataset/canada-2          26.0MB/s ± 0%  25.9MB/s ± 1%    ~     (p=0.460 n=4+5)
UnmarshalDataset/citm_catalog-2    21.6MB/s ± 2%  21.7MB/s ± 1%    ~     (p=0.952 n=5+5)
UnmarshalDataset/twitter-2         46.4MB/s ± 0%  47.1MB/s ± 0%  +1.53%  (p=0.008 n=5+5)
UnmarshalDataset/code-2            25.0MB/s ± 1%  25.1MB/s ± 1%    ~     (p=0.175 n=5+5)
UnmarshalDataset/example-2         49.2MB/s ± 2%  49.7MB/s ± 0%  +1.07%  (p=0.016 n=5+4)
Unmarshal/SimpleDocument/struct-2  19.2MB/s ± 1%  19.3MB/s ± 0%  +0.74%  (p=0.048 n=5+5)
Unmarshal/SimpleDocument/map-2     13.0MB/s ± 1%  13.0MB/s ± 0%    ~     (p=0.254 n=5+5)
Unmarshal/ReferenceFile/struct-2   94.0MB/s ± 0%  97.1MB/s ± 0%  +3.35%  (p=0.008 n=5+5)
Unmarshal/ReferenceFile/map-2      62.8MB/s ± 2%  64.7MB/s ± 0%  +3.06%  (p=0.008 n=5+5)
Unmarshal/HugoFrontMatter-2        37.9MB/s ± 1%  38.4MB/s ± 0%  +1.49%  (p=0.008 n=5+5)
```
@pelletier pelletier added the performance Issue related to a performance problem or pull request improving performance. label Nov 4, 2021
@pelletier pelletier merged commit 6617e7e into v2 Nov 4, 2021
@pelletier pelletier deleted the ascii-table branch November 4, 2021 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Issue related to a performance problem or pull request improving performance.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant