You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
python: encrypt converts each value twice, once to check its range and once to write it #1640
The Python SDK, stackencrypt in languages/python, encrypts a list of models with Cipher.encrypt. For each field of each model, its Rust extension reads the Python value, checks it against the field's type (for example, that an int fits a 16-bit Smallint), and writes it into the input that the engine stack-encrypt encrypts.
Problem
Each value is converted into the engine's scalar type twice.
languages/python/crates/engine/src/encrypt.rs:224 calls values::scalar to check the range rules first, so that a value that does not fit is refused with its own error code and the field's name.
encrypt.rs:280 then calls values::write, which converts the same value again to write it (languages/python/crates/core/src/values.rs:137).
The result is correct. The cost is a second conversion of every value in every encrypt call. Nobody has measured that cost. In a large batch it may be visible next to the request to ZeroKMS (CipherStash's key service), or it may not.
Proposal
Measure first: time encrypt on a large batch, such as 10,000 models of mixed field types, with and without the second conversion.
If the cost is worth removing, have values::write take the scalar that values::scalar already made, or have write return the misfit itself. Either changes values::write's signature, and every caller of it.
If the cost is not worth removing, close this issue with the numbers.
Activity