Repository navigation
html: avoid copying tag names and attributes without NUL bytes - #272
Open
thevilledev wants to merge 1 commit into
Open
thevilledev wants to merge 1 commit into
thevilledev wants to merge 1 commit into
Conversation
CL 781883 made TagName and TagAttr replace NUL bytes in tag names and
attribute keys and values using bytes.ReplaceAll. ReplaceAll returns a
copy even if there is nothing to replace, so since then every tag name,
attribute key and attribute value is allocated, although they rarely
contain a NUL byte.
Only copy them if they contain a NUL byte, as Text already does.
Otherwise return slices of the tokenizer's buffer, as before CL 781883,
which the documentation of Raw allows.
goos: darwin
goarch: arm64
pkg: golang.org/x/net/html
cpu: Apple M1 Max
│ master.txt │ new.txt │
│ sec/op │ sec/op vs base │
Parser-10 820.1µ ± 0% 761.2µ ± 0% -7.19% (p=0.000 n=10)
RawLevelTokenizer-10 276.3µ ± 0% 277.0µ ± 1% ~ (p=0.190 n=10)
LowLevelTokenizer-10 437.9µ ± 0% 371.0µ ± 1% -15.27% (p=0.000 n=10)
HighLevelTokenizer-10 516.0µ ± 1% 451.1µ ± 2% -12.59% (p=0.000 n=10)
geomean 475.7µ 433.4µ -8.89%
│ master.txt │ new.txt │
│ B/s │ B/s vs base │
Parser-10 90.89Mi ± 0% 97.92Mi ± 0% +7.74% (p=0.000 n=10)
RawLevelTokenizer-10 269.8Mi ± 0% 269.1Mi ± 1% ~ (p=0.190 n=10)
LowLevelTokenizer-10 170.2Mi ± 0% 200.9Mi ± 1% +18.03% (p=0.000 n=10)
HighLevelTokenizer-10 144.4Mi ± 1% 165.2Mi ± 2% +14.40% (p=0.000 n=10)
geomean 156.7Mi 172.0Mi +9.75%
│ master.txt │ new.txt │
│ B/op │ B/op vs base │
Parser-10 575.4Ki ± 0% 539.6Ki ± 0% -6.22% (p=0.000 n=10)
RawLevelTokenizer-10 10.23Ki ± 0% 10.23Ki ± 0% ~ (p=1.000 n=10) ¹
LowLevelTokenizer-10 42.29Ki ± 0% 10.23Ki ± 0% -75.80% (p=0.000 n=10)
HighLevelTokenizer-10 128.15Ki ± 0% 92.36Ki ± 0% -27.93% (p=0.000 n=10)
geomean 75.16Ki 47.80Ki -36.40%
¹ all samples are equal
│ master.txt │ new.txt │
│ allocs/op │ allocs/op vs base │
Parser-10 11.189k ± 0% 7.470k ± 0% -33.24% (p=0.000 n=10)
RawLevelTokenizer-10 678.0 ± 0% 678.0 ± 0% ~ (p=1.000 n=10) ¹
LowLevelTokenizer-10 4397.0 ± 0% 678.0 ± 0% -84.58% (p=0.000 n=10)
HighLevelTokenizer-10 7.094k ± 0% 3.375k ± 0% -52.42% (p=0.000 n=10)
geomean 3.922k 1.845k -52.96%
¹ all samples are equal
Fixes golang/go#82128
Contributor
|
This PR (HEAD: c0fead6) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/net/+/848445. Important tips:
|
Contributor
|
Message from Jean-Baptiste Lernout: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/848445. |
Contributor
|
Message from Ville Vesilehto: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/848445. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CL 781883 made TagName and TagAttr replace NUL bytes in tag names and
attribute keys and values using bytes.ReplaceAll. ReplaceAll returns a
copy even if there is nothing to replace, so since then every tag name,
attribute key and attribute value is allocated, although they rarely
contain a NUL byte.
Only copy them if they contain a NUL byte, as Text already does.
Otherwise return slices of the tokenizer's buffer, as before CL 781883,
which the documentation of Raw allows.
goos: darwin
goarch: arm64
pkg: golang.org/x/net/html
cpu: Apple M1 Max
│ master.txt │ new.txt │
│ sec/op │ sec/op vs base │
Parser-10 820.1µ ± 0% 761.2µ ± 0% -7.19% (p=0.000 n=10)
RawLevelTokenizer-10 276.3µ ± 0% 277.0µ ± 1% ~ (p=0.190 n=10)
LowLevelTokenizer-10 437.9µ ± 0% 371.0µ ± 1% -15.27% (p=0.000 n=10)
HighLevelTokenizer-10 516.0µ ± 1% 451.1µ ± 2% -12.59% (p=0.000 n=10)
geomean 475.7µ 433.4µ -8.89%
Parser-10 90.89Mi ± 0% 97.92Mi ± 0% +7.74% (p=0.000 n=10)
RawLevelTokenizer-10 269.8Mi ± 0% 269.1Mi ± 1% ~ (p=0.190 n=10)
LowLevelTokenizer-10 170.2Mi ± 0% 200.9Mi ± 1% +18.03% (p=0.000 n=10)
HighLevelTokenizer-10 144.4Mi ± 1% 165.2Mi ± 2% +14.40% (p=0.000 n=10)
geomean 156.7Mi 172.0Mi +9.75%
Parser-10 575.4Ki ± 0% 539.6Ki ± 0% -6.22% (p=0.000 n=10)
RawLevelTokenizer-10 10.23Ki ± 0% 10.23Ki ± 0% ~ (p=1.000 n=10) ¹
LowLevelTokenizer-10 42.29Ki ± 0% 10.23Ki ± 0% -75.80% (p=0.000 n=10)
HighLevelTokenizer-10 128.15Ki ± 0% 92.36Ki ± 0% -27.93% (p=0.000 n=10)
geomean 75.16Ki 47.80Ki -36.40%
¹ all samples are equal
Parser-10 11.189k ± 0% 7.470k ± 0% -33.24% (p=0.000 n=10)
RawLevelTokenizer-10 678.0 ± 0% 678.0 ± 0% ~ (p=1.000 n=10) ¹
LowLevelTokenizer-10 4397.0 ± 0% 678.0 ± 0% -84.58% (p=0.000 n=10)
HighLevelTokenizer-10 7.094k ± 0% 3.375k ± 0% -52.42% (p=0.000 n=10)
geomean 3.922k 1.845k -52.96%
¹ all samples are equal
Fixes golang/go#82128