Skip to content

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

Closed
amneeksingh wants to merge 3 commits intomainfrom
perf/cache-paramsql-keyswitchdown
Closed

Performance: cache paramsQl for HYBRID KeySwitchDown (implements TODO)#1184
amneeksingh wants to merge 3 commits intomainfrom
perf/cache-paramsql-keyswitchdown

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.

dsuponitskiy and others added 3 commits April 20, 2026 11:15
…int8_t and removed their aliases from inttypes.h (#1168)

* Remove usshort and uschar from inttypes.h and replaced their usage with uint16_t and uint8_t

* Removed usint from inttypes.h and replaced its usage with uint32_t

* Pass integer parameter by value to function instead of by constant reference

---------

Co-authored-by: Dmitriy Suponitskiy <dsuponitskiy@dualitytech.com>
Added funding acknowledgment for ARPA-H research.
@amneeksingh amneeksingh closed this May 1, 2026
@amneeksingh amneeksingh deleted the perf/cache-paramsql-keyswitchdown branch May 1, 2026 10:28
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.

4 participants