RFR: 8314199: Initial size PBEKeyFactory#validTypes is not up-to-date

Valerie Peng valeriep at openjdk.org
Mon Oct 9 20:25:56 UTC 2023


On Mon, 9 Oct 2023 20:13:48 GMT, Jamil Nimeh <jnimeh at openjdk.org> wrote:

>> Do you think we'll lose performance in a meaningful way? One of the guarantees of HashSet is constant-time operations. 
>> 
>> There is no such guarantee for Set. The number of members is probably small enough, relatively speaking, to not affect things much at creation time (and we only do this once); however, lookup time (in `engineGetKeySpec` and `engineTranslateKey`) might take a small hit if these methods are called repeatedly. 
>> 
>> Let me know whether you think this is a valid concern. Thanks!
>
> I think there could be sight timing variations between `HashSet` and whatever Set implementation is returned by `Set.of()` but creation only happens once as you stated, and iterations over 20-ish elements just seems like the variance would be negligible in any real-world use cases.

How about changing to use the `HashSet(Collection<? extends E> c)` constructor? First construct a collection with the various algorithms and then construct `validType` w/ this collection. `validType` can be made unmodifiable also since it's read only.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16103#discussion_r1350759168


More information about the security-dev mailing list