Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fall back properly if chosen factory class isn't working. #28

Merged
merged 6 commits into from
Sep 22, 2020

Conversation

JonathanLennox
Copy link
Member

Don't bother benchmarking the chosen factory class; it either works or it doesn't.

Also includes a few minor other cleanups.

@JonathanLennox
Copy link
Member Author

Note: this is the important parts of #26, without the PKCS11 change which is much less urgent.

// unnecessary. Technically though, the specified CipherFactory may
// malfunction. That is why FACTORY_CLASS_NAME is selected after it has
// proven itself functional.
boolean chosenFactoryClass = (factory.getClass().equals(Aes.factoryClass));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra parens on purpose?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, no, I reorganized this from an if statement.


if (chosenFactoryClass)
{
if (minFactory != null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand this well. If this loop iteration is for the user-configured factory class, return the fastest factory. If a previous non-user-configured factory was faster, we short-circuit and return it (the faster one)?

Should that return factory instead of minFactory?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, elsewhere in the code I reorganize the list so the user-configured factory class is always first, so we avoid profiling factories we don't need to. But I agree that's fragile and confusing.

I've reorganized it now, is it clearer?

{
benchmark.run(cipher);
}
}

long startTime = System.nanoTime();
for (int i = 0; i < NUM_BENCHMARKS; i++)
for (int i = 0; i < numBenchmarks; i++)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should line 329 use numBenchmarks instead of NUM_BENCHMARKS? I guess in practice it doesn't matter

{
for (Class<?> clazz : factoryClasses)
Class<?>[] newFactoryClasses;
if (add)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all of this is equivalent to factoryClasses = ArrayUtils.add(factoryClasses, Class.class, factoryClass); (from jitsi-utils)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite - I want to put the new factory class first, whereas ArrayUtils.add would seem to put it last.

@JonathanLennox JonathanLennox merged commit 5317529 into jitsi:master Sep 22, 2020
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.

2 participants