You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf: reuse global/cached signers & verifiers, fix callback signing with dynamic secret, and fast-path static request verification #438
I have searched existing issues to ensure the issue has not already been raised
Issue
Several hot-path regressions and overhead sources exist in reply.jwtSign() and request.jwtVerify():
Promise-mode reply.jwtSign(payload) bypasses the precompiled global signer:
When replySign(payload, options, next) converts omitted options for its Promise wrapper, it sets options = {} before calling reply[jwtSignName](payload, options, cb). Because {} is truthy, useLocalSigner stays true, causing every await reply.jwtSign(payload) call to go through steed.waterfall and recompile createSigner(...) (including createPrivateKey / detectPrivateKeyAlgorithm for RSA/ECDSA PEM keys) on every single request instead of reusing the startup signer.
Callback-mode reply.jwtSign(payload, cb) throws TypeError: cb is not a function when secret is a dynamic function:
When secret is a function (e.g. (_req, _payload, cb) => cb(null, key) or async () => key), reply.jwtSign(payload, cb) sets useLocalSigner = false and calls the global signer(payload), whose isAsync key fetcher invokes secretCallbackSign with (data, fastJwtCb) instead of (request, payload, cb).
Dynamic signer/verifier caching gaps:
reply.jwtSign() has no dynamic signer cache (unlike validatorCache in getVerifier).
validatorCache only caches typeof options.key === 'string', skipping Buffer keys, and is unbounded (Map with no eviction limit).
In requestVerify, const useGlobalOptions = !options is evaluated before if (typeof options === 'function'), so callback calls request.jwtVerify(cb) evaluate useGlobalOptions = false, create an unreachable wrapper Promise, and miss validatorCache / global verifier.
When configured with a static public key and default options without decode.checkTyp, requestVerify still pre-decodes the token with decode(token) (double-decoding the JWT and bypassing fast-jwt's verifier LRU cache), merges options redundantly in lookupToken, and dispatches through steed.waterfall.
Expected behavior
Reuse the startup signer directly (without steed.waterfall) in reply.jwtSign(payload) / reply.jwtSign(payload, cb) when secret is static and no per-call options are given.
Fix reply.jwtSign(payload, cb) for dynamic secret functions and share bounded dynamic caching (supporting non-empty string and Buffer keys, capped at 1000 entries) across signerCache and validatorCache.
Detect function-only options before checking useGlobalOptions / Promise mode in requestVerify, and add a synchronous fast path for global static-key verification (when !decodeOptions.checkTyp) using the global verifier directly while preserving error wrapping and trusted / formatUser semantics.
This issue mostly duplicates the description of perf: reuse signer/verifier caches, fix callback signing, and fast-path static verify #439. When you already have a fix or an improvement ready, feel free to open the PR directly: there's no need for a separate issue, it avoids keeping two threads in sync, and it prevents other people from picking up the issue and opening duplicate PRs for the same change, which is something I've been noticing on some open issues lately.
When you open a PR, please document everything there, so the whole context lives in one place.
Each PR is branched cleanly from main, contains dedicated unit tests, achieves 100% test coverage, and passes all TypeScript and ESLint checks. Ready for review!
Activity
Tony133 commentedon Nov 15, 2026
Thanks for looking into this!
A couple of suggestions:
reply.jwtSign(payload, cb)with a dynamic secretSmaller PRs are much easier to review, and the bug fix can land quickly without waiting on the perf discussion.
Once all three PRs have been opened, we will close this issue and do the review directly on the PRs.
TalhaHunter101 commentedon Nov 16, 2026
Hi @Tony133,
As requested, I have split the work into three dedicated, standalone PRs:
fix: reply.jwtSign(payload, cb) with a dynamic secret)perf: reuse the global signer for static keys)perf: bounded signer/verifier cache and static verify fast path)Each PR is branched cleanly from
main, contains dedicated unit tests, achieves 100% test coverage, and passes all TypeScript and ESLint checks. Ready for review!