Overview
This report summarizes three notable performance optimization pull requests merged in the past two weeks across popular open-source Golang projects. Each PR targets a specific bottleneck — ranging from algorithmic complexity reduction to in-memory caching — and delivers measurable, significant speedups.
PR #1 — prometheus/prometheus · Merged Feb 16, 2026
tsdb: Optimize LabelValues API performance
Repository: prometheus/prometheus (55,000+ stars) PR: #18069 Author: mishraa-G | Merged by: bboreham
Problem
The FindIntersectingPostings function suffered from severe O(N) performance degradation when processing matchers with sparse intersections. If a matcher’s posting ID was far ahead of the current candidate (e.g., matcher at 1,000,000 while candidate was at 0), the function would call Next() approximately 1,000,000 times — resulting in query timeouts for large datasets.
Root Cause
The function relied on sequential iteration via Next() for each candidate posting, with no ability to skip ahead. The LabelValues API path was therefore dramatically slower than the Series API for equivalent queries.
Solution
Replace Next() calls with Seek() operations on the candidate iterator. This enables logarithmic-time skipping through non-matching ranges, mirroring the approach already used in the faster Series API.
Key Code Changes
Before — sequential Next() iteration:
| |
After — logarithmic Seek() jumping:
| |
New benchmark for the sparse intersection case:
| |
Benchmark Results
| Scenario | Before | After | Improvement |
|---|---|---|---|
| Sparse intersection (new benchmark) | ~919,901 ns/op | ~836 ns/op | 99.91% |
| High-overlap (existing benchmark) | 2.718 ms/op | 1.408 ms/op | 48.20% |
Review Highlights
Reviewer bboreham called it “a great find” and requested method consolidation and naming clarity. The author implemented the suggestions by renaming seek() to seekHead() and removing unused code paths. Verified with go test ./tsdb/index/... showing no regressions.
PR #2 — grafana/grafana · Merged Feb 10, 2026
Library Panels: Add a Folder Tree Cache for getAllHandler
Repository: grafana/grafana (65,000+ stars) PR: #117475 Author: RafaelPaulovic | Reviewed by: JohnnyQQQQ, renatolabs
Problem
Grafana instances with large deployments (14,000+ folders and 1,800+ library panels) experienced unacceptable latency when retrieving all library panels via getAllHandler. Response times reached up to 52 seconds on unified storage and 16 seconds on legacy storage — caused by repeated folder service calls for every element.
Root Cause
The getAllHandler made a separate folder service call for each library panel to resolve folder metadata. This produced N+1 query behavior proportional to the number of library panels, with no caching between requests.
Solution
Introduce a FolderTree data structure providing O(1) lookups for folder hierarchy data, backed by a request-scoped in-memory cache with a 30-second TTL, shared per user/organization combination.
Key Code Changes
New FolderTree data structure (pkg/services/folder/tree.go):
| |
Tree construction and key methods:
| |
Cache layer (pkg/services/libraryelements/cache.go):
| |
Performance Results
| Request Type | Before | After (1st request) | After (2nd request) |
|---|---|---|---|
| Unified Storage | 52.3s | 8.4s | 0.4s |
| Legacy Storage | 16.4s | 6.9s | 0.4s |
Review Highlights
The PR was approved by JohnnyQQQQ and renatolabs after discussion on cache scope — ultimately made global with fallback support for cache misses. Successfully backported to release-12.3.3.
PR #3 — grafana/grafana · Merged Feb 9, 2026
Alerting: Improve Performance of Folder Access Checks
Repository: grafana/grafana (65,000+ stars) PR: #117080 Author: alexander-akhmetov | Milestone: 12.4.x
Problem
In Grafana’s alerting system, every folder access permission check triggered a call to the database-backed scope resolver. For high-frequency alerting rule evaluations, this produced unnecessary database round-trips even when the required folder hierarchy information was already available in memory.
Root Cause
The HasAccessInFolder() and AuthorizeAccessInFolder() functions always delegated to the database-backed access control evaluators with no fast path for cases where folder fullpath UIDs were pre-computed and accessible locally.
Solution
Convert Namespace from a type alias to a struct carrying a FullpathUIDs field. Introduce checkFolderAccessByFullpath() as an in-memory fast path — falling back to the database only when fullpath data is unavailable.
Key Code Changes
Updated Namespace struct (adding fullpath data):
| |
New interface for in-memory permission checks:
| |
New fast-path function checkFolderAccessByFullpath:
| |
Updated permission check with fast path:
| |
Database query updated to include fullpath UIDs:
| |
Impact
Eliminates database calls for the common case where folder hierarchy data is pre-computed, significantly reducing latency in alerting rule evaluation loops. Reviewer Yuri Tseretian commented: “This is a great improvement.”
Comprehensive test coverage was added for: permissions on target/parent folders, deeply nested hierarchies, mixed permission scenarios, and fallback behavior when fullpath UIDs are unavailable.
Summary Table
| # | Repository | PR | Title | Stars | Merged | Key Improvement |
|---|---|---|---|---|---|---|
| 1 | prometheus/prometheus | #18069 | tsdb: Optimize LabelValues API performance | 55k+ | Feb 16, 2026 | 99.91% faster (O(N)→O(log N)) via Seek() |
| 2 | grafana/grafana | #117475 | Library Panels: folder tree cache for getAllHandler | 65k+ | Feb 10, 2026 | 52s → 0.4s via O(1) FolderTree cache |
| 3 | grafana/grafana | #117080 | Alerting: Improve performance of folder access checks | 65k+ | Feb 9, 2026 | Eliminates DB calls via in-memory fullpath evaluation |
Report generated: 2026-02-18