Skip to content

More efficient key sign lookups#209

Merged
ueno merged 1 commit intoueno:masterfrom
djberg96:encrypt_plus_sign
Feb 6, 2026
Merged

More efficient key sign lookups#209
ueno merged 1 commit intoueno:masterfrom
djberg96:encrypt_plus_sign

Conversation

@djberg96
Copy link
Contributor

@djberg96 djberg96 commented Feb 6, 2026

The issue is that Key.find is expensive (~7ms per call) because it creates a new GPGME context each time. When using encrypt(..., sign: true, signers: ...), the code was making two separate Key.find calls, one for recipients, and one for signers. This doubled the key lookup overhead, making encrypt+sign with explicit signers significantly slower.

Performance Improvement: I added a resolve_keys_for_signing helper method in crypto.rb that reuses already-fetched recipient Key objects when the signer matches a recipient (by fingerprint, key ID, or email), and only calls Key.find for signers that aren't already in the recipient list.

In local benchmarks, the explicit signer case went from being 78% slower than encrypt-only to only 24% slower, which is now in line with the expected overhead of signing.

Addresses #156

Copy link
Owner

@ueno ueno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great; thank you also for adding the benchmark script!

@ueno ueno merged commit 8ad8400 into ueno:master Feb 6, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants