Skip to content

Conversation

@joshua-spacetime
Copy link
Collaborator

@joshua-spacetime joshua-spacetime commented May 7, 2025

Description of Changes

Before this change we would hash subscription queries after acquiring the tx lock.

Hashing requires that we parse first so that we can determine if the query is parameterized with :sender. However our parser sqlparser is quite slow, resulting in Subscribe being 3x slower than Unsubscribe according to some benchmarks.

This patch doesn't change the parser at all. It just moves it so that it doesn't block other transactions.

This patch now generates query hashes without parsing. It does so by generating two hashes and seeing if either is currently tracked by the subscription manager. Hashes are generated outside of the tx lock.

API and ABI breaking changes

None

Expected complexity level and risk

1

Testing

  • Performance bot test

@joshua-spacetime joshua-spacetime self-assigned this May 7, 2025
@joshua-spacetime joshua-spacetime requested a review from jsdt May 7, 2025 20:13
Copy link
Contributor

@jsdt jsdt left a comment

Choose a reason for hiding this comment

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

This will save a lot of work for queries that already have subscribers, but it looks like we could avoid double-parsing for new queries with a little refactoring.

@joshua-spacetime joshua-spacetime force-pushed the joshua/perf/query-hashing branch from aca58d1 to 75b0c28 Compare May 8, 2025 20:16
@joshua-spacetime joshua-spacetime changed the title Parse and hash subscription queries before acquiring tx lock Hash subscription queries before acquiring tx lock May 8, 2025
@joshua-spacetime joshua-spacetime requested a review from jsdt May 8, 2025 20:42
gefjon and others added 2 commits May 9, 2025 12:08
Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
Signed-off-by: joshua-spacetime <josh@clockworklabs.io>
@joshua-spacetime joshua-spacetime enabled auto-merge May 9, 2025 16:27
@joshua-spacetime joshua-spacetime added this pull request to the merge queue May 9, 2025
Merged via the queue into master with commit 2699c03 May 9, 2025
19 of 20 checks passed
@joshua-spacetime joshua-spacetime deleted the joshua/perf/query-hashing branch May 9, 2025 17:09
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.

4 participants