Skip to content

perf: add SignerContext caching for ring signature optimization#48

Open
jorgecuesta wants to merge 1 commit intomainfrom
perf/signer-context-cache
Open

perf: add SignerContext caching for ring signature optimization#48
jorgecuesta wants to merge 1 commit intomainfrom
perf/signer-context-cache

Conversation

@jorgecuesta
Copy link

Summary

  • Add signerContextCache (sync.Map) to Signer struct to cache SignerContext instances per ring
  • Implement getOrCreateSignerContext() for thread-safe cache access
  • Update Sign() to use ring-go's SignWithContext() with cached context
  • Add ClearSignerContextCache() for session rollover cleanup
  • Update ring-go dependency to include SignerContext optimization (feat: add SignerContext for optimized repeated signing ring-go#3)

Problem

Ring signatures consume significant CPU time when signing relay requests. The existing implementation recomputes expensive cryptographic operations (ScalarBaseMul, hashToCurve, key image) on every sign call, even when using the same ring within a session.

Solution

Cache the pre-computed SignerContext per ring. Since rings are tied to sessions (same sessionEndHeight = same ring), this cache is highly effective for the typical use case of signing multiple requests within the same session.

Benchmark Results (ring-go)

Ring Size Improvement
2 ~17.4% faster
4 ~12.6% faster
8 ~5.7% faster

Usage Note

Callers should invoke ClearSignerContextCache() on session rollover to prevent unbounded cache growth.

Test Plan

  • All existing tests pass
  • Build succeeds
  • Benchmarks verify performance improvement

@jorgecuesta jorgecuesta requested a review from oten91 December 19, 2025 19:29
@jorgecuesta jorgecuesta self-assigned this Dec 19, 2025
@jorgecuesta jorgecuesta added the enhancement New feature or request label Dec 19, 2025
- Add signerContextCache (sync.Map) to Signer struct to cache
  SignerContext instances per ring
- Implement getOrCreateSignerContext() for thread-safe cache access
- Update Sign() to use ring-go's SignWithContext() with cached context
- Add ClearSignerContextCache() for session rollover cleanup
- Update ring-go dependency to include SignerContext optimization

This optimization avoids redundant cryptographic operations
(ScalarBaseMul, hashToCurve, key image computation) when signing
multiple requests with the same ring within a session.

Benchmark improvements (ring-go):
- Ring size 2: ~17.4% faster
- Ring size 4: ~12.6% faster
- Ring size 8: ~5.7% faster
@jorgecuesta jorgecuesta force-pushed the perf/signer-context-cache branch from 8c5d637 to 1fca845 Compare December 19, 2025 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant