Skip to content

Mark schema template replacements as Stable to enable Replacer cache#1242

Open
IgorDeo wants to merge 1 commit intoriverqueue:masterfrom
IgorDeo:fix-sqlctemplate-schema-stable
Open

Mark schema template replacements as Stable to enable Replacer cache#1242
IgorDeo wants to merge 1 commit intoriverqueue:masterfrom
IgorDeo:fix-sqlctemplate-schema-stable

Conversation

@IgorDeo
Copy link
Copy Markdown

@IgorDeo IgorDeo commented May 6, 2026

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

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
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.

schemaTemplateParam should mark schema replacement as Stable: true to enable Replacer cache

1 participant