Skip to content

Conversation

@njvrzm
Copy link
Contributor

@njvrzm njvrzm commented Nov 24, 2025

What this PR does / why we need it:
This changes MiddlewareHandler to build its middleware chain once when instantiated rather than doing it for each request. The Handler returned by handlerFromMiddlewares will be functionally identical any time it's called; calling it once will save a lot of allocations, although since this way is also simpler and more readable I haven't actually tried to benchmark it.

@njvrzm njvrzm force-pushed the njvrzm/build-middlewares-once branch from 90a1b27 to ea54e11 Compare November 24, 2025 13:01
@grafana-plugins-platform-bot grafana-plugins-platform-bot bot moved this from 📬 Triage to 🔬 In review in Plugins Platform / Grafana Community Nov 24, 2025
@njvrzm
Copy link
Contributor Author

njvrzm commented Nov 24, 2025

The "incompatible changes" error is a red herring btw - I changed some receivers from value to pointer because there were inconsistent receiver types. We're returning a pointer anyway. The only way this could end up being incompatible is if someone's calling HandlerFromMiddlewares and dereferencing the result, and I think in that case I'd say: don't do that.

I can revert the receiver type changes, though, if there's any objection.

@njvrzm njvrzm merged commit 055c27c into main Nov 25, 2025
6 of 7 checks passed
@njvrzm njvrzm deleted the njvrzm/build-middlewares-once branch November 25, 2025 09:01
@github-project-automation github-project-automation bot moved this from 🔬 In review to 🚀 Shipped in Plugins Platform / Grafana Community Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🚀 Shipped

Development

Successfully merging this pull request may close these issues.

2 participants