Skip to content

Commit

Permalink
perf(compiler): avoid big copy of server keys
Browse files Browse the repository at this point in the history
we inline the server key serialization so that we only make small copies
  • Loading branch information
youben11 committed Dec 10, 2024
1 parent 5979a08 commit b0cd9a2
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions compilers/concrete-compiler/compiler/lib/Common/Keysets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,28 @@ Keyset Keyset::fromProto(concreteprotocol::Keyset::Reader reader) {

Message<concreteprotocol::Keyset> Keyset::toProto() const {
auto output = Message<concreteprotocol::Keyset>();
auto serverProto = server.toProto();
// we inlined call to server.toProto() to avoid a single big copy of the
// server keyset. With this, we only do copies of individual keys.
auto serverKeyset = output.asBuilder().initServer();
serverKeyset.initLweBootstrapKeys(server.lweBootstrapKeys.size());
for (size_t i = 0; i < server.lweBootstrapKeys.size(); i++) {
serverKeyset.getLweBootstrapKeys().setWithCaveats(
i, server.lweBootstrapKeys[i].toProto().asReader());
}

serverKeyset.initLweKeyswitchKeys(server.lweKeyswitchKeys.size());
for (size_t i = 0; i < server.lweKeyswitchKeys.size(); i++) {
serverKeyset.getLweKeyswitchKeys().setWithCaveats(
i, server.lweKeyswitchKeys[i].toProto().asReader());
}

serverKeyset.initPackingKeyswitchKeys(server.packingKeyswitchKeys.size());
for (size_t i = 0; i < server.packingKeyswitchKeys.size(); i++) {
serverKeyset.getPackingKeyswitchKeys().setWithCaveats(
i, server.packingKeyswitchKeys[i].toProto().asReader());
}
// client serialization is not inlined as keys aren't that big
auto clientProto = client.toProto();
output.asBuilder().setServer(serverProto.asReader());
output.asBuilder().setClient(clientProto.asReader());
return output;
}
Expand Down

0 comments on commit b0cd9a2

Please sign in to comment.