Skip to content

Performance: cache paramsQl for HYBRID KeySwitchDown (implements TODO)#1185

Open
amneeksingh wants to merge 2 commits intodevfrom
perf/cache-paramsql-clean
Open

Performance: cache paramsQl for HYBRID KeySwitchDown (implements TODO)#1185
amneeksingh wants to merge 2 commits intodevfrom
perf/cache-paramsql-clean

Conversation

@amneeksingh
Copy link
Copy Markdown
Collaborator

This PR implements the TODO in keyswitch-hybrid.cpp to avoid rebuilding paramsQl on every call in the HYBRID keyswitch path.

Background:
KeySwitchDown and KeySwitchDownFirstElement currently reconstruct paramsQl (ILDCRTParams for the first sizeQl towers of Q) from paramsQlP on every call, allocating vectors and a new ILDCRTParams. This runs in a hot path during relinearization and ApproxModDown.

Changes:

  • Precompute and cache m_paramsQlHybrid (params for first 1..sizeQ towers of Q) in CryptoParametersRNS when m_ksTechnique == HYBRID.
  • Add getter GetParamsQlHybrid(sizeQl) in rns-cryptoparameters.h.
  • Use cached params in KeySwitchDown / KeySwitchDownFirstElement.
  • Preserve behavior via fallback to original inline construction when cache is not populated (e.g., after deserialization).
  • Factor fallback into a single helper MakeParamsQlFromQlP() to remove duplicated code between the two functions.

Notes:

  • No cryptographic semantics are changed.
  • Cache is built once during parameter initialization and is read-only thereafter (thread-safe).
  • No API breaking changes.

Files changed:

  • src/pke/include/schemerns/rns-cryptoparameters.h
  • src/pke/lib/schemerns/rns-cryptoparameters.cpp
  • src/pke/lib/keyswitch/keyswitch-hybrid.cpp

Happy to add a regression test or benchmark comparison if that would help the review.

@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.

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.

1 participant