{{ message }}
Repository navigation
feat(sync-service): index for array contains - #2359
Merged
Merged
Conversation
robacourt
force-pushed
the
rob/index-array-contains
branch
8 times, most recently
from
February 24, 2025 15:45
707acda to
11fa653
Compare
robacourt
force-pushed
the
rob/index-array-contains
branch
from
February 24, 2025 15:52
11fa653 to
643c266
Compare
robacourt
marked this pull request as ready for review
February 24, 2025 16:03
robacourt
force-pushed
the
rob/index-array-contains
branch
from
February 24, 2025 16:33
643c266 to
10c5854
Compare
alco
approved these changes
Feb 25, 2025
icehaunter
approved these changes
Feb 25, 2025
icehaunter
left a comment
Contributor
There was a problem hiding this comment.
Very good job! 🔥 My only nitpick would be nested update formatting, but I've relayed that to you in DMs, feel free to address or not
robacourt
force-pushed
the
rob/index-array-contains
branch
from
February 25, 2025 14:49
765c282 to
bef3973
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This PR seeks to address trigger.dev's WAL lag issues by adding two optimisations to where clause filtering:
Allow multiple conditions in a where clause to be optimised (not just one)
This feature alone should halve the processing time for trigger.dev as they have many where clauses in the form
WHERE runtimeEnvironmentId = ? AND batchId = ?where if a change matched theruntimeEnvironmentIdit would then have to iterate through thebatchIds. Now it doesn't - thebatchIdcondition is indexed as well.Optimise where clauses that have a condition in the form 'array_field @> array_const'
Trigger.dev's other problematic where clauses are in the form
WHERE runtimeEnvironmentId = ? AND runTags @> ?and this feature optimises the@>operation. The algorithm for this optimisation can be seen in the InclusionIndex module.Comparing the performance of this index against the current method shows quite a dramatic difference:

Here you can see it performs well with 100k shapes (which for trigger.dev would be 100k shapes with the same

runtimeEnvironmentId, in other words 100k shapes per user)Both of the charts above are based on a shape array size of 3 and a change array size of 10 which is typical for trigger.dev.
The algorithm seems to scale roughly linearly with change array size:

The algorithm seems to scale well with shape array size for a fixed change array size (10):
