Skip to content

perf(templater): skip template engine for strings without {{#2820

Merged
andreynering merged 1 commit intogo-task:mainfrom
romnn:perf/skip-template-parsing-for-static-literals
May 1, 2026
Merged

perf(templater): skip template engine for strings without {{#2820
andreynering merged 1 commit intogo-task:mainfrom
romnn:perf/skip-template-parsing-for-static-literals

Conversation

@romnn
Copy link
Copy Markdown
Contributor

@romnn romnn commented Apr 30, 2026

First commit from #2819 with comments removed. Speeds up task --list from 13.8 seconds to ~5 seconds on a large monorepo. See original PR for details.

Copy link
Copy Markdown
Contributor

@trulede trulede left a comment

Choose a reason for hiding this comment

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

LGTM.

If you like to experiment further, AI suggests this at the start of the function.

func ReplaceWithExtra[T any](v T, cache *Cache, extra map[string]any) T {
	if cache.err != nil {
		return v
	}

	// Optimization: Direct check for common simple types
	// If it's a string and doesn't have "{{", return immediately.
	if s, ok := any(v).(string); ok {
		if !strings.Contains(s, "{{") {
			return v
		}
	}

@romnn romnn force-pushed the perf/skip-template-parsing-for-static-literals branch from 95c4358 to 451d264 Compare May 1, 2026 11:46
@romnn
Copy link
Copy Markdown
Contributor Author

romnn commented May 1, 2026

Great suggestion, this indeed saved another 1.5 to 2 seconds on our repo!

I've folded it into my single commit as per the contributing guide and decided to add a very concise comment in both places to highlight that those short circuits are purely performance optimizations and not behavioral. I think those are stylistically fine and improve clarity, but I can also adjust or remove them.

@trulede
Copy link
Copy Markdown
Contributor

trulede commented May 1, 2026

Great suggestion, this indeed saved another 1.5 to 2 seconds on our repo!

That is a great outcome! The PR is fine.

Copy link
Copy Markdown
Member

@andreynering andreynering left a comment

Choose a reason for hiding this comment

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

Very simple, yet we never thought about doing this optimization 🙂

Thank you!

@andreynering andreynering merged commit 46f5db2 into go-task:main May 1, 2026
15 checks passed
andreynering added a commit that referenced this pull request May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants