Skip to content

*: reduce CPU overhead on hot paths#5108

Open
lidezhu wants to merge 3 commits into
masterfrom
ldz/optmize-cpu0520
Open

*: reduce CPU overhead on hot paths#5108
lidezhu wants to merge 3 commits into
masterfrom
ldz/optmize-cpu0520

Conversation

@lidezhu
Copy link
Copy Markdown
Collaborator

@lidezhu lidezhu commented May 20, 2026

What problem does this PR solve?

Issue Number: close #5107

What is changed and how it works?

Before this pr:
image

After this pr:
image

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Questions

Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?

Release note

Please refer to [Release Notes Language Style Guide](https://pingcap.github.io/tidb-dev-guide/contribute-to-tidb/release-notes-style-guide.html) to write a quality release note.

If you don't think this PR needs a release note then fill it with `None`.

@ti-chi-bot ti-chi-bot Bot added do-not-merge/needs-linked-issue release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels May 20, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 20, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 20, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign kennytm for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

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

Details 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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

Warning

Rate limit exceeded

@lidezhu has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 50 minutes and 40 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9e3ef891-139c-4663-9f67-843e286ff1d9

📥 Commits

Reviewing files that changed from the base of the PR and between 00684df and 23b67df.

📒 Files selected for processing (5)
  • downstreamadapter/eventcollector/dispatcher_stat.go
  • downstreamadapter/eventcollector/helper.go
  • logservice/logpuller/region_event_handler.go
  • utils/dynstream/stream.go
  • utils/dynstream/stream_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ldz/optmize-cpu0520

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ti-chi-bot ti-chi-bot Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 20, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request focuses on performance optimizations by reducing overhead in logging and metrics collection. It introduces explicit log level checks before debug statements to prevent unnecessary field evaluation and implements caching for Prometheus metric observers to avoid the cost of WithLabelValues in performance-critical paths. A review comment suggests simplifying a switch statement in region_event_handler.go by removing a redundant case that re-assigns a default value.

Comment thread logservice/logpuller/region_event_handler.go
@lidezhu lidezhu changed the title logpuller,dynstream: cache metric handles on hot path *: reduce CPU overhead on hot paths May 20, 2026
@lidezhu lidezhu marked this pull request as ready for review May 20, 2026 10:42
@ti-chi-bot ti-chi-bot Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 20, 2026
@wuhuizuo
Copy link
Copy Markdown
Contributor

/test ?

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 21, 2026

@wuhuizuo: The following commands are available to trigger required jobs:

/test pull-build
/test pull-cdc-kafka-integration-heavy
/test pull-cdc-kafka-integration-light
/test pull-cdc-mysql-integration-heavy
/test pull-cdc-mysql-integration-light
/test pull-cdc-storage-integration-heavy
/test pull-cdc-storage-integration-light
/test pull-check
/test pull-error-log-review
/test pull-unit-test

The following commands are available to trigger optional jobs:

/test pull-build-next-gen
/test pull-cdc-kafka-integration-heavy-next-gen
/test pull-cdc-kafka-integration-light-next-gen
/test pull-cdc-mysql-integration-heavy-next-gen
/test pull-cdc-mysql-integration-heavy-v7-5
/test pull-cdc-mysql-integration-heavy-v8-1
/test pull-cdc-mysql-integration-light-next-gen
/test pull-cdc-mysql-integration-light-v7-5
/test pull-cdc-mysql-integration-light-v8-1
/test pull-cdc-pulsar-integration-heavy
/test pull-cdc-pulsar-integration-heavy-next-gen
/test pull-cdc-pulsar-integration-light
/test pull-cdc-pulsar-integration-light-next-gen
/test pull-cdc-storage-integration-heavy-next-gen
/test pull-cdc-storage-integration-light-next-gen
/test pull-unit-test-next-gen

Use /test all to run the following jobs that were automatically triggered:

pull-error-log-review
Details

In response to this:

/test ?

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.

@wuhuizuo
Copy link
Copy Markdown
Contributor

/test pull_cdc_storage_integration_light_next_gen

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 21, 2026

@wuhuizuo: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

/test pull-build
/test pull-cdc-kafka-integration-heavy
/test pull-cdc-kafka-integration-light
/test pull-cdc-mysql-integration-heavy
/test pull-cdc-mysql-integration-light
/test pull-cdc-storage-integration-heavy
/test pull-cdc-storage-integration-light
/test pull-check
/test pull-error-log-review
/test pull-unit-test

The following commands are available to trigger optional jobs:

/test pull-build-next-gen
/test pull-cdc-kafka-integration-heavy-next-gen
/test pull-cdc-kafka-integration-light-next-gen
/test pull-cdc-mysql-integration-heavy-next-gen
/test pull-cdc-mysql-integration-heavy-v7-5
/test pull-cdc-mysql-integration-heavy-v8-1
/test pull-cdc-mysql-integration-light-next-gen
/test pull-cdc-mysql-integration-light-v7-5
/test pull-cdc-mysql-integration-light-v8-1
/test pull-cdc-pulsar-integration-heavy
/test pull-cdc-pulsar-integration-heavy-next-gen
/test pull-cdc-pulsar-integration-light
/test pull-cdc-pulsar-integration-light-next-gen
/test pull-cdc-storage-integration-heavy-next-gen
/test pull-cdc-storage-integration-light-next-gen
/test pull-unit-test-next-gen

Use /test all to run the following jobs that were automatically triggered:

pull-error-log-review
Details

In response to this:

/test pull_cdc_storage_integration_light_next_gen

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.

@wuhuizuo
Copy link
Copy Markdown
Contributor

/test pull-cdc-storage-integration-light-next-gen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

Cache Prometheus metric handles on hot paths

2 participants