Repository navigation
perf: set the database charset once per connection in sbpp_main - #82
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 of 8 tasks
WareZ57
approved these changes
Oct 28, 2026
WareZ57
left a comment
There was a problem hiding this comment.
Read this against the rest of sbpp_main, looks correct to me.
DBis only ever assigned inGotDatabase()and is never closed or replaced, andDatabase.Connect(GotDatabase, ...)is only called whileDBis null (OnPluginStart,OnRebuildAdminCache, and the retry timer #83 adds). Sodb != DBmeans exactly "this is a new connection", and the three calls per map fromOnRebuildAdminCache()with the current handle skipSetCharset().- No leak or handle overwrite: there's no path where a second successful connect replaces a live
DB. - The
SET NAMES utf8mb4fallback still runs once on a new connection ifSetCharset()fails, which is fine. - Built locally with spcomp 1.12.0.7259 (same
-i includeas CI): all 6 plugins compile with no errors or warnings, both on this branch alone and merged with #83.sbpp_main.spmerges cleanly with #83; only the two newCHANGELOG.mdentries conflict, as you already noted.
LGTM.
This was referenced Oct 29, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
On css-ze, our production profiler shows
sbpp_main::OnRebuildAdminCacheat 13.5 ms per call (p50 12 ms, p99 24.4 ms, 15.9 s of main-thread time over 7 days, 1179 calls). It runs about three times per map change (overrides, groups, admins) and on everysm_reloadadmins. Each call stalls the server for close to a full tick (15 ms at 66 tick), and the p99 calls take more than a tick.When the database is already connected,
OnRebuildAdminCache()callsGotDatabase(DB, "", 0)again for each cache part.GotDatabase()then callsDB.SetCharset("utf8mb4")each time. On MySQL this is a synchronous call on the main thread:LockForFullAtomicOperation()), so it waits for any threaded query in flight on that connection, including the queries queued by the previous cache part;mysql_set_character_set()sendsSET NAMESand waits for the reply, a full round trip to the database.The charset only needs to be set once per connection.
mysql_set_character_set()also stores the charset in the connection options, and the SourceMod MySQL driver enablesMYSQL_OPT_RECONNECT, so the charset survives the driver's automatic reconnects too. sbpp_main never closes or replacesDB, so the connection stays the same for the life of the plugin.GotDatabase()assignsDBand callsSetCharset()(with the existing asyncSET NAMESfallback) only when it gets a new handle (db != DB). Calls fromOnRebuildAdminCache()with the current handle skip it.GotDatabase()still runs on every call, as before: config reset,InsertServerInfo(), the overrides/groups/admins queries, andCheckConnectedClientBans().2.2.10-srcdslab. The plugin version comes from the release tag (sbpp_version.incstaysdev).Expected gain: the per-call cost should drop from about 12 to 24 ms to well under 1 ms. That removes about 40 ms of main-thread stall per map change, plus one stall per manual admin reload.
Behaviour
Unchanged. The connection is set to
utf8mb4once when it is established, exactly as before. Later rebuilds reuse the same handle, which already has that charset. The only difference: ifSetCharset()fails on the first connect, it is no longer retried on every rebuild. The asyncSET NAMES utf8mb4fallback is still sent once on that connection.Test plan
sm_reloadadmins. Check that admins, groups and overrides load, that names with UTF-8/emoji are still stored correctly in bans, and thatOnRebuildAdminCachedrops in the profiler🤖 Generated with Claude Code