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

slices: optimize Compact and CompactFunc #64273

Closed
wants to merge 7 commits into from

Conversation

go101
Copy link

@go101 go101 commented Nov 20, 2023

Try to save a comparison in the loop bodies of Compact and CompactFunc.

Note: due to #64272, some bound checks still fail to be removed.

                        │ old.txt  │             new.txt              │
                        │   sec/op    │   sec/op     vs base                │

Compact/nil-4 4.191n ± 9% 3.402n ± 1% -18.84% (p=0.000 n=10)
Compact/one-4 5.289n ± 2% 4.553n ± 2% -13.93% (p=0.000 n=10)
Compact/sorted-4 9.865n ± 0% 6.882n ± 1% -30.24% (p=0.000 n=10)
Compact/2_items-4 11.10n ± 2% 12.11n ± 2% +9.00% (p=0.000 n=10)
Compact/unsorted-4 9.831n ± 3% 6.918n ± 2% -29.62% (p=0.000 n=10)
Compact/many-4 16.40n ± 4% 14.90n ± 1% -9.20% (p=0.000 n=10)
Compact/dup_start-4 29.87n ± 0% 28.06n ± 3% -6.04% (p=0.001 n=10)
Compact_Large/all_dup-4 13.11µ ± 0% 13.12µ ± 0% ~ (p=0.971 n=10)
Compact_Large/no_dup-4 6.972µ ± 0% 5.806µ ± 0% -16.73% (p=0.000 n=10)
CompactFunc/nil-4 5.300n ± 0% 5.309n ± 1% ~ (p=0.289 n=10)
CompactFunc/one-4 6.051n ± 1% 6.442n ± 3% +6.46% (p=0.000 n=10)
CompactFunc/sorted-4 16.24n ± 1% 12.79n ± 2% -21.24% (p=0.000 n=10)
CompactFunc/2_items-4 17.89n ± 1% 17.75n ± 0% -0.75% (p=0.000 n=10)
CompactFunc/unsorted-4 16.26n ± 0% 12.83n ± 1% -21.07% (p=0.000 n=10)
CompactFunc/many-4 30.71n ± 1% 29.07n ± 0% -5.32% (p=0.000 n=10)
CompactFunc/dup_start-4 78.94n ± 1% 67.19n ± 1% -14.89% (p=0.000 n=10)
CompactFunc_Large/all_dup-4 3.277m ± 0% 3.692m ± 2% +12.67% (p=0.000 n=10)
CompactFunc_Large/no_dup-4 4.019m ± 0% 2.826m ± 1% -29.68% (p=0.000 n=10)
geomean 109.6n 96.99n -11.47%

@gopherbot
Copy link

This PR (HEAD: d642ac1) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/543661.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot
Copy link

Message from Gopher Robot:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/543661.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Xu Liu:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/543661.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Xu Liu:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/543661.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Xu Liu:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/543661.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Xu Liu:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/543661.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

This PR (HEAD: a912a34) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/543661.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot
Copy link

This PR (HEAD: d2236ae) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/543661.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot
Copy link

Message from Xu Liu:

Patch Set 3:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/543661.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

This PR (HEAD: 5df3a7a) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/543661.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot
Copy link

Message from Xu Liu:

Patch Set 6:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/543661.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

This PR (HEAD: cea3d93) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/543661.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot
Copy link

Message from Keith Randall:

Patch Set 8: Auto-Submit+1 Code-Review+2 Commit-Queue+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/543661.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Go LUCI:

Patch Set 8:

Dry run: CV is trying the patch.

Bot data: {"action":"start","triggered_at":"2023-11-28T21:43:24Z","revision":"017dc099225d00d172b4e7017fe1a7fd45c1bd33"}


Please don’t reply on this GitHub thread. Visit golang.org/cl/543661.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Keith Randall:

Patch Set 8: Code-Review+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/543661.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Keith Randall:

Patch Set 8: -Commit-Queue


Please don’t reply on this GitHub thread. Visit golang.org/cl/543661.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Go LUCI:

Patch Set 8:

This CL has passed the run


Please don’t reply on this GitHub thread. Visit golang.org/cl/543661.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Go LUCI:

Patch Set 8: LUCI-TryBot-Result+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/543661.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Xu Liu:

Patch Set 8:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/543661.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Keith Randall:

Patch Set 8:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/543661.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Ian Lance Taylor:

Patch Set 8:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/543661.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Xu Liu:

Patch Set 8:

(3 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/543661.
After addressing review feedback, remember to publish your drafts!

gopherbot pushed a commit that referenced this pull request Apr 26, 2024
Try to save a comparison in the loop bodies of Compact and CompactFunc.

Note: due to #64272, some bound checks still fail to be removed.

                            │ old.txt  │             new.txt              │
                            │   sec/op    │   sec/op     vs base                │
Compact/nil-4                 4.191n ± 9%   3.402n ± 1%  -18.84% (p=0.000 n=10)
Compact/one-4                 5.289n ± 2%   4.553n ± 2%  -13.93% (p=0.000 n=10)
Compact/sorted-4              9.865n ± 0%   6.882n ± 1%  -30.24% (p=0.000 n=10)
Compact/2_items-4             11.10n ± 2%   12.11n ± 2%   +9.00% (p=0.000 n=10)
Compact/unsorted-4            9.831n ± 3%   6.918n ± 2%  -29.62% (p=0.000 n=10)
Compact/many-4                16.40n ± 4%   14.90n ± 1%   -9.20% (p=0.000 n=10)
Compact/dup_start-4           29.87n ± 0%   28.06n ± 3%   -6.04% (p=0.001 n=10)
Compact_Large/all_dup-4       13.11µ ± 0%   13.12µ ± 0%        ~ (p=0.971 n=10)
Compact_Large/no_dup-4        6.972µ ± 0%   5.806µ ± 0%  -16.73% (p=0.000 n=10)
CompactFunc/nil-4             5.300n ± 0%   5.309n ± 1%        ~ (p=0.289 n=10)
CompactFunc/one-4             6.051n ± 1%   6.442n ± 3%   +6.46% (p=0.000 n=10)
CompactFunc/sorted-4          16.24n ± 1%   12.79n ± 2%  -21.24% (p=0.000 n=10)
CompactFunc/2_items-4         17.89n ± 1%   17.75n ± 0%   -0.75% (p=0.000 n=10)
CompactFunc/unsorted-4        16.26n ± 0%   12.83n ± 1%  -21.07% (p=0.000 n=10)
CompactFunc/many-4            30.71n ± 1%   29.07n ± 0%   -5.32% (p=0.000 n=10)
CompactFunc/dup_start-4       78.94n ± 1%   67.19n ± 1%  -14.89% (p=0.000 n=10)
CompactFunc_Large/all_dup-4   3.277m ± 0%   3.692m ± 2%  +12.67% (p=0.000 n=10)
CompactFunc_Large/no_dup-4    4.019m ± 0%   2.826m ± 1%  -29.68% (p=0.000 n=10)
geomean                       109.6n        96.99n       -11.47%

Change-Id: Ia4c78fa62e7e9f4ff6a39d0e0a0a84cecf79b9cb
GitHub-Last-Rev: cea3d93
GitHub-Pull-Request: #64273
Reviewed-on: https://go-review.googlesource.com/c/go/+/543661
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Joedian Reid <joedian@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
@gopherbot
Copy link

This PR is being closed because golang.org/cl/543661 has been merged.

@gopherbot gopherbot closed this Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants