Skip to content

perf: small optimization for already closed done chan in xcotenxt.WithDone#2171

Open
asmyasnikov wants to merge 10 commits into
masterfrom
xcontext-with-done
Open

perf: small optimization for already closed done chan in xcotenxt.WithDone#2171
asmyasnikov wants to merge 10 commits into
masterfrom
xcontext-with-done

Conversation

@asmyasnikov

@asmyasnikov asmyasnikov commented May 22, 2026

Copy link
Copy Markdown
Member

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Other information

@github-actions

github-actions Bot commented May 22, 2026

Copy link
Copy Markdown

summary

Inferred base version: v3.139.6
Suggested version: v3.139.7

@asmyasnikov asmyasnikov changed the title perf: small optimization for already closed done chan in xcotenxt.Wit… perf: small optimization for already closed done chan in xcotenxt.WithDone May 22, 2026
@codecov-commenter

codecov-commenter commented May 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.59%. Comparing base (3a3badf) to head (c225b96).
⚠️ Report is 33 commits behind head on master.

Files with missing lines Patch % Lines
internal/xcontext/done.go 92.30% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2171      +/-   ##
==========================================
- Coverage   75.64%   75.59%   -0.05%     
==========================================
  Files         437      437              
  Lines       45030    45047      +17     
==========================================
- Hits        34063    34055       -8     
- Misses       9019     9039      +20     
- Partials     1948     1953       +5     
Flag Coverage Δ
experiment 75.48% <92.30%> (-0.06%) ⬇️
go-1.21.x 72.77% <84.61%> (-0.11%) ⬇️
go-1.26.x 75.56% <92.30%> (-0.08%) ⬇️
integration 57.49% <34.61%> (-0.23%) ⬇️
macOS 45.28% <84.61%> (+<0.01%) ⬆️
ubuntu 75.59% <92.30%> (-0.05%) ⬇️
unit 45.29% <84.61%> (-0.01%) ⬇️
windows 45.28% <84.61%> (-0.02%) ⬇️
ydb-24.4 57.06% <34.61%> (-0.19%) ⬇️
ydb-edge 57.26% <34.61%> (-0.24%) ⬇️
ydb-latest 57.19% <34.61%> (-0.27%) ⬇️
ydb-nightly 75.48% <92.30%> (-0.06%) ⬇️

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

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes internal/xcontext.WithDone() for the case where the provided done channel is already closed, avoiding creation of a cancelable child context and associated AfterFunc setup.

Changes:

  • Added a lightweight doneAlreadySignaledCtx fast-path that returns an already-done context when done is closed.
  • Introduced a package-level pre-closed Done() channel and a no-op cancel func for the fast-path.
  • Added benchmarks for WithDone to measure the closed/open channel cases.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
internal/xcontext/done.go Adds a fast-path context wrapper + shared closed channel to reduce allocations when done is already closed.
internal/xcontext/done_test.go Adds benchmarks for WithDone performance/allocations across scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/xcontext/done.go Outdated
Comment thread internal/xcontext/done.go Outdated
Comment thread internal/xcontext/done.go
Comment thread internal/xcontext/done_test.go
Comment thread internal/xcontext/done_test.go
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI and others added 2 commits May 22, 2026 22:17
…al double-close

Agent-Logs-Url: https://github.com/ydb-platform/ydb-go-sdk/sessions/87d0f664-4bc2-45ed-a0f1-a408829b77a7

Co-authored-by: asmyasnikov <14202262+asmyasnikov@users.noreply.github.com>

Copilot AI commented May 22, 2026

Copy link
Copy Markdown
Contributor

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • invalid_host
    • Triggering command: /tmp/go-build2911943860/b562/credentials.test /tmp/go-build2911943860/b562/credentials.test -test.paniconexit0 -test.count=1 -test.timeout=1m0s /tmp/go-build2911943860/b475/vet.cfg uf@v1.36.10/internal/filedesc/bu-p (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI commented May 22, 2026

Copy link
Copy Markdown
Contributor

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • invalid_host
    • Triggering command: /tmp/go-build1710531782/b562/credentials.test /tmp/go-build1710531782/b562/credentials.test -test.paniconexit0 -test.count=1 -test.timeout=1m0s /tmp/go-build1710531782/b478/vet.cfg 8233508/b135/_pk-errorsas 3m30/LWOPomVVPXf-ifaceassert ux_amd64/compile-nilfunc (dns block)
    • Triggering command: /tmp/go-build39286722/b562/credentials.test /tmp/go-build39286722/b562/credentials.test -test.paniconexit0 -test.count=1 -test.timeout=1m0s /tmp/go-build39286722/b359/vet.cfg k/ydb-go-sdk/ydbGOINSECURE k/ydb-go-sdk/ydbGOMOD /opt/hostedtoolcGOMODCACHE go1.24.13 -c=4 -nolocalimports /opt/hostedtoolcGO111MODULE -o /tmp/go-build128GOINSECURE -trimpath /usr/bin/go -d main -lang=go1.24 go (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread internal/xcontext/done.go
Comment thread internal/xcontext/done_test.go

Copilot AI commented May 23, 2026

Copy link
Copy Markdown
Contributor

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • invalid_host
    • Triggering command: /tmp/go-build1079472391/b562/credentials.test /tmp/go-build1079472391/b562/credentials.test -test.paniconexit0 -test.count=1 -test.timeout=1m0s /tmp/go-build1079472391/b457/vet.cfg 2211871/b110/_pk-errorsas x64/src/compress-ifaceassert ux_amd64/compile-nilfunc (dns block)
    • Triggering command: /tmp/go-build1173223067/b562/credentials.test /tmp/go-build1173223067/b562/credentials.test -test.paniconexit0 -test.count=1 -test.timeout=1m0s GOROOT GOSUMDB GOWORK 7569522/b591=&gt; -p latform/ydb-go-s-o -lang=go1.24 /opt/hostedtoolc-trimpath -o ff36e04fadbbb298-d -trimpath (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI commented May 23, 2026

Copy link
Copy Markdown
Contributor

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • invalid_host
    • Triggering command: /tmp/go-build54549844/b562/credentials.test /tmp/go-build54549844/b562/credentials.test -test.paniconexit0 -test.count=1 -test.timeout=1m0s /tmp/go-build54549844/b459/vet.cfg --local oSnB/GcRJkGUVQZc-ifaceassert ux_amd64/compile-nilfunc 6406090/b147/ (dns block)
    • Triggering command: /tmp/go-build1137366009/b562/credentials.test /tmp/go-build1137366009/b562/credentials.test -test.paniconexit0 -test.count=1 -test.timeout=1m0s /tmp/go-build1137366009/b502/vet.cfg EgsDDG8e6 0s (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@asmyasnikov asmyasnikov added SLO and removed no slo labels Jun 14, 2026
@github-actions github-actions Bot removed the SLO label Jun 14, 2026
@github-actions

Copy link
Copy Markdown

🌋 SLO Test Results

🟡 8 workload(s) tested — 2 workload(s) exceeded warning thresholds

Commit: c12478d · View run

Workload Thresholds Duration Report
native-query 🟢 OK 10m 1s 📄 Report
database-sql-table 🟢 OK 10m 1s 📄 Report
database-sql-query 🟡 Warning 10m 1s 📄 Report
native-table-over-query-service 🟢 OK 10m 1s 📄 Report
native-table 🟡 Warning 10m 1s 📄 Report
native-table-node-hints 🟢 OK 10m 11s 📄 Report
native-bulk-upsert 🟢 OK 10m 📄 Report
native-query-node-hints 🟢 OK 0s 📄 Report

Threshold violations:

database-sql-query:

  • read_retry_attempts: Value 0.08 > warning max 0
  • write_retry_attempts: Value 0.01 > warning max 0

native-table:

  • read_retry_attempts: Value 0.05 > warning max 0
  • write_retry_attempts: Value 0.02 > warning max 0

Generated by ydb-slo-action

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants