Visitar URL original
Release SQLite aggregate instances when queries finish by 1ndahous3 · Pull Request #9014 · RustPython/RustPython · GitHub
Skip to content

Release SQLite aggregate instances when queries finish - #9014

Open
1ndahous3 wants to merge 1 commit into
RustPython:mainfrom
1ndahous3:sqlite_aggregate_lifetime
Open

1ndahous3 wants to merge 1 commit into
RustPython:mainfrom
1ndahous3:sqlite_aggregate_lifetime

Conversation

@1ndahous3

@1ndahous3 1ndahous3 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Release Python aggregate and window-function instances when a query finishes, fails, or its cursor is closed before completion.
  • Run aggregate destructors after releasing SQLite locks, including nested callbacks.
  • Avoid allocating aggregate context during finalization and check missing contexts before dereferencing them.

Performance

100 aggregate groups with 64 KiB of state each, after closing the connection and collecting garbage:

Retained state Before After
Aggregate instances 100 0
Aggregate payload 6.25 MiB 0

AI assistance

Written with Codex (GPT-6), reviewed by a human before submission.

Summary by CodeRabbit

  • Bug Fixes
    • Improved cleanup of resources used by SQLite aggregate and window functions after queries complete, fail, or are interrupted by closing a cursor.
    • Improved reliability when SQLite callbacks interact with connections or cursors during query execution and cleanup, including commit and rollback operations.
    • SQLite now reports an out-of-memory error when it cannot allocate aggregate-function context.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T22:13:29.521304Z ab1b733 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d907fcf9-d3e1-4e5b-be5c-acee28338902
📥 Commits

Reviewing files that changed from the base of the PR and between 54e47cd and ab1b733.

📒 Files selected for processing (2)
  • crates/stdlib/src/_sqlite3.rs
  • extra_tests/snippets/stdlib_sqlite.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The SQLite module now wraps connection, cursor, blob, callback-registration, and handle cleanup paths in deferred-drop scopes. Aggregate callbacks use explicit context creation or lookup and handle missing contexts. Tests cover callback object collection and cleanup during nested SQLite operations.

Changes

SQLite resource lifetimes

Layer / File(s) Summary
Aggregate callback context and lifetime
crates/stdlib/src/_sqlite3.rs, extra_tests/snippets/stdlib_sqlite.py
Aggregate callbacks now distinguish context creation from lookup, handle absent context or stored objects, and defer releasing the object during finalization. Tests cover aggregate and window object collection.
Deferred-drop scopes across SQLite operations
crates/stdlib/src/_sqlite3.rs, extra_tests/snippets/stdlib_sqlite.py
Connection, cursor, blob, and SQLite handle paths now use deferred-drop scopes. Tests exercise cleanup during cursor and connection operations, callback replacement, and nested SQLite work.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Suggested reviewers: ever0de, youknowone

Merge Risk: ⚪ Minimal · up to ab1b7

This change releases SQLite aggregate and window-function instances when queries finish, fail, or are closed early, and it adds tests for the release behavior. No concrete merge-blocking risk was identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 20.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 69 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: releasing SQLite aggregate instances when queries finish.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@codspeed

codspeed Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 15.24%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 61 untouched benchmarks
⏩ 4 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ rustpython[frozenset.py] 411.6 µs 357.2 µs +15.24%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing 1ndahous3:sqlite_aggregate_lifetime (ab1b733) with main (54e47cd)

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@youknowone

Copy link
Copy Markdown
Member

@ever0de could you review this patch?

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.

2 participants