pingcap / pingcap/tidb

tracking: reduce TiDB SQL-path CPU and allocations

Open
#70,649 0 comments 0 reactions 0 assignees View on GitHub
type/enhancement
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Enhancement

Reduce transient allocations and repeated CPU work on common TiDB SQL paths. CPU profiles and caller-representative microbenchmarks identified a set of small, independent costs that accumulate across planning, execution, distributed requests, and result encoding.

## Scope

- [ ] #70650 reduces planner preprocessing and range-construction overhead.
- [ ] #70651 reduces allocations in executor, expression, chunk, and row-codec hot paths.
- [ ] #70652 reduces distributed SQL and coprocessor request overhead.
- [ ] #70653 reduces SQL protocol and statement-infrastructure overhead.

Each scope item is kept in a separate PR so that it can be reviewed and benchmarked by the corresponding maintainers.

## Review constraints

- Preserve SQL semantics, error behavior, concurrency behavior, observability, and public APIs.
- Prefer local fast paths with explicit ownership and bounded lifetimes.
- Avoid duplicated JSON, wire-protocol, or row serialization that could silently diverge when formats evolve.
- Avoid cross-package representation or lifetime invariants that materially increase maintenance cost.
- Accept a change only when representative common paths improve without a material protected-case regression or retained-memory tradeoff.

## Validation

The retained changes have caller-representative Go benchmarks and correctness or ownership tests. The grouped branches pass their targeted tests, representative benchmarks with `-benchmem`, `git diff --check`, and `go build ./cmd/tidb-server` on the current `master` baseline.

A second-pass audit removed a rebased connection-alive-checker optimization
that was obsolete on current master and added packet-count, flush/error,
response-count, paging-key, range-split, encoding-fallback, and staged PointGet
coverage for the remaining stateful optimizations.

End-to-end workload impact and individual microbenchmark evidence will be documented in the linked PRs without attributing unsupported gains to a single change.

Contributor guide

Open the contributing guide

Research direction

Start with the linked scope issue for the area you want to investigate: #70650, #70651, #70652, or #70653. Read its targeted tests and caller-representative Go benchmarks, then validate with -benchmem, git diff --check, and go build ./cmd/tidb-server. Done means the targeted correctness or ownership tests pass and the representative common path improves without protected-case or retained-memory regressions.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
databases, performance
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.