Mark schema template replacements as Stable to enable Replacer cache#1242
Open
IgorDeo wants to merge 1 commit intoriverqueue:masterfrom
Open
Mark schema template replacements as Stable to enable Replacer cache#1242IgorDeo wants to merge 1 commit intoriverqueue:masterfrom
IgorDeo wants to merge 1 commit intoriverqueue:masterfrom
Conversation
schemaTemplateParam (and the schema replacement in ColumnExists) never set Stable: true, so the sqlctemplate.Replacer cache introduced in riverqueue#802 is bypassed on every query. This causes regexp.ReplaceAllStringFunc to run on every SQL query, allocating a new string each time. Under production throughput this creates enough allocation pressure to cause visible memory growth — we observed +29MB in 16 minutes on a worker running river.Start() with continuous job polling. The schema value comes from the client config and is constant for the lifetime of a River client, so marking it Stable is safe. With this change, the regex runs once per unique SQL string and then serves from cache. Fixes all three drivers: riverpgxv5, riverdatabasesql, riversqlite. Fixes riverqueue#1241
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.
schemaTemplateParam (and the schema replacement in ColumnExists) never set Stable: true, so the sqlctemplate.Replacer cache introduced in #802 is bypassed on every query. This causes regexp.ReplaceAllStringFunc to run on every SQL query, allocating a new string each time.
The schema value comes from the client config and is constant for the lifetime of a River client, so marking it Stable is safe. With this change, the regex runs once per unique SQL string and then serves from cache.
Fixes all three drivers: riverpgxv5, riverdatabasesql, riversqlite.
Fixes #1241