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

table: memoize TableCommon.getCols #53605

Merged
merged 6 commits into from
May 29, 2024
Merged

Conversation

ekexium
Copy link
Member

@ekexium ekexium commented May 28, 2024

What problem does this PR solve?

Issue Number: close #53604

Problem Summary:

getCols does duplicated calculation, which wastes CPU time.

What changed and how does it work?

Memoize this function.

Proportion of time in the microbenchmark of AddRecord (with pipelined DML and ART memdb)

Previous:
image

This PR:
image

Check List

Tests

  • Unit test - micro benchmark + existing test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-tests-checked release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 28, 2024
Copy link

tiprow bot commented May 28, 2024

Hi @ekexium. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ekexium ekexium force-pushed the memorize-getcols branch from 2c2d860 to b91042e Compare May 28, 2024 04:50
@ekexium ekexium force-pushed the memorize-getcols branch from b91042e to 9bad6ad Compare May 28, 2024 04:56

// avoid duplicated calculations of Cols
// mode -> cols
getColsCache [][]*table.Column
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could use hiddenColumns, visibleColumns and publicColumns instead of this one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When are these fields supposed to be set (before this PR)? I don't find anywhere initializing them

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems never be setted. /cc @zimulala

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems #50062 introduced the regression. It removed the default initialization, but mistakenly making them never initialized.

Copy link

codecov bot commented May 28, 2024

Codecov Report

Attention: Patch coverage is 97.05882% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 74.8076%. Comparing base (df64c34) to head (d2755c1).
Report is 29 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #53605        +/-   ##
================================================
+ Coverage   72.4222%   74.8076%   +2.3854%     
================================================
  Files          1505       1507         +2     
  Lines        430553     438363      +7810     
================================================
+ Hits         311816     327929     +16113     
+ Misses        99427      90324      -9103     
- Partials      19310      20110       +800     
Flag Coverage Δ
integration 49.4569% <77.9411%> (?)
unit 71.4283% <97.0588%> (+0.0267%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 53.9957% <ø> (ø)
parser ∅ <ø> (∅)
br 50.4742% <ø> (+9.0871%) ⬆️

@ekexium ekexium force-pushed the memorize-getcols branch from 2c772d1 to 55050d3 Compare May 28, 2024 05:42
Signed-off-by: ekexium <[email protected]>
@ekexium ekexium changed the title table: memorize TableCommon.getCols table: memoize TableCommon.getCols May 28, 2024
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 28, 2024
@ekexium
Copy link
Member Author

ekexium commented May 28, 2024

Test failed because IMPORT INTO concurrently calls AddRecord, which calls WritableConstraint(), resulting in data race.
I'd rather let the caller that knows its concurrent behavior initialize these fields than introducing something like sync.Once here.

@ekexium ekexium force-pushed the memorize-getcols branch from 38d8988 to a4214cf Compare May 29, 2024 04:41
Signed-off-by: ekexium <[email protected]>
@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label May 29, 2024
@ekexium
Copy link
Member Author

ekexium commented May 29, 2024

/retest

Copy link

tiprow bot commented May 29, 2024

@ekexium: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

ti-chi-bot bot commented May 29, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Defined2014, zimulala

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm approved and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels May 29, 2024
Copy link

ti-chi-bot bot commented May 29, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-05-29 06:57:36.091251401 +0000 UTC m=+2846009.848386973: ☑️ agreed by Defined2014.
  • 2024-05-29 07:28:48.600745154 +0000 UTC m=+2847882.357880725: ☑️ agreed by zimulala.

@ekexium
Copy link
Member Author

ekexium commented May 29, 2024

/retest

Copy link

tiprow bot commented May 29, 2024

@ekexium: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot ti-chi-bot bot merged commit 22c41d0 into pingcap:master May 29, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TableCommon.getCols() can be memorized
4 participants