Skip to content

Performance: cache paramsQl for HYBRID KeySwitchDown#1185

Merged
yspolyakov merged 5 commits into
devfrom
perf/cache-paramsql-clean
Jun 9, 2026
Merged

Performance: cache paramsQl for HYBRID KeySwitchDown#1185
yspolyakov merged 5 commits into
devfrom
perf/cache-paramsql-clean

Conversation

@amneeksingh

@amneeksingh amneeksingh commented May 1, 2026

Copy link
Copy Markdown
Collaborator

This PR implements the TODO in keyswitch-hybrid.cpp by avoiding repeated paramsQl construction in the HYBRID keyswitch path.

Changes

  • Precompute m_paramsQlHybrid in CryptoParametersRNS::PrecomputeCRTTables() for the first 1..sizeQ towers of Q when HYBRID key switching is used.
  • Add GetParamsQlHybrid(sizeQl) in rns-cryptoparameters.h.
  • Use the cached params in KeySwitchDown() and KeySwitchDownFirstElement() instead of rebuilding ILDCRTParams on each call.

Notes

  • No cryptographic semantics are changed.
  • The cache is built during parameter initialization and read afterward.
  • No API breaking changes.

@amneeksingh

Copy link
Copy Markdown
Collaborator Author

(UTGENERAL_ENCODING.packed_int_ptxt_encoding_DCRTPoly_prime_cyclotomics) appears to be pre-existing and unrelated to this PR — it involves prime cyclotomic encoding, not HYBRID KeySwitch or paramsQl caching. Please let me know if you'd like me to investigate further.

@yspolyakov

Copy link
Copy Markdown
Contributor

(UTGENERAL_ENCODING.packed_int_ptxt_encoding_DCRTPoly_prime_cyclotomics) appears to be pre-existing and unrelated to this PR — it involves prime cyclotomic encoding, not HYBRID KeySwitch or paramsQl caching. Please let me know if you'd like me to investigate further.

Are you saying you saw an error when running this unit test? If yes, please create an issue and copy the error output there.

@yspolyakov

Copy link
Copy Markdown
Contributor

Oh. I see the output. Let me rerun the CI.

@yspolyakov
yspolyakov force-pushed the perf/cache-paramsql-clean branch from 1563cf9 to 83c06e2 Compare May 28, 2026 02:52
@yspolyakov yspolyakov added this to the Release 1.6.0 milestone May 28, 2026
@yspolyakov yspolyakov added the optimization Improves performance label May 28, 2026
@yspolyakov yspolyakov linked an issue May 28, 2026 that may be closed by this pull request
@yspolyakov
yspolyakov requested a review from dsuponitskiy May 28, 2026 03:30
@dsuponitskiy
dsuponitskiy force-pushed the perf/cache-paramsql-clean branch 2 times, most recently from 1e419fd to 0fe8599 Compare May 28, 2026 23:09
@dsuponitskiy dsuponitskiy self-assigned this Jun 2, 2026
@dsuponitskiy dsuponitskiy changed the title Performance: cache paramsQl for HYBRID KeySwitchDown (implements TODO) Performance: cache paramsQl for HYBRID KeySwitchDown Jun 2, 2026
@dsuponitskiy
dsuponitskiy force-pushed the perf/cache-paramsql-clean branch from 97186d1 to baaaf8c Compare June 2, 2026 19:16
@pascoec
pascoec self-requested a review June 2, 2026 20:01
@yspolyakov
yspolyakov merged commit 81d367e into dev Jun 9, 2026
19 checks passed
@dsuponitskiy
dsuponitskiy deleted the perf/cache-paramsql-clean branch June 9, 2026 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimization Improves performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Precompute paramsQl in hybrid key switching

5 participants