Comments (4)
Thank you for the suggestion, but I don't think this is the right way forward.
Reallocating the buffer on every call will generate unnecessary GC pressure and decrease throughput in cases where the OTP generator is not contested by multiple threads.
If multi-threaded throughput is a priority, callers can create multiple thread-local OTP generator instances. That gives all the benefits of an uncontested generator without the cost of repeated allocations (albeit at the cost of ThreadLocal
overhead), and so the performance penalty is avoidable. By contrast, the performance penalty in an allocation-per-call model would be unavoidable.
Again, I appreciate the suggestion! I recognize there may be more to do to document best practices in a multi-threaded environment; let's look into those instead of changing the allocation model.
from java-otp.
I think you're vastly overestimating the pressure garbage collection will place on the system, but okay.
from java-otp.
Well, maybe so. I ran a benchmark and it looks like the difference isn't statistically significant.
In the process, though, I remembered the other, much more important reason why things are designed the way they are: the Mac
instance. Mac
operations are not thread safe, and so we either need some way to enforce exclusive access (which we're doing now by synchronizing) or we need a new Mac
for every invocation. Reallocating a buffer is, indeed, pretty cheap. Reallocating a Mac
is more expensive, and that does result in a throughput drop in the 10-15% range in my benchmark runs. It also complicates the NoSuchAlgorithmException
-handling story a bit (there are ways forward; they're just a little clumsier than we're doing now).
So, fair enough: I should have run the benchmarks before making an argument about the performance effects of a design change. That said, now that I'm armed with benchmark results (and a fresher memory of the situation), I stand by the decision to leave things as they are.
from java-otp.
Hey, @BenTels, I was thinking about this a bit more and think I found a good way forward. If the spirit moves you, I'd be curious what you think of #42.
from java-otp.
Related Issues (20)
- Release 0.1 not supported HOT 2
- TOTP Generating different value with a particular timestep HOT 3
- OTP generator return 5 digits instead of 6 HOT 1
- JPMS module HOT 1
- When first digit of generated pin is 0, it is being handled as octal number HOT 3
- Import secrets
- the result of below code is different with the one of google authenticator HOT 2
- HOTP generator return zero otp code HOT 2
- Only one empty TimeBasedOneTimePasswordGenerator constructor available HOT 4
- NoSuchMethodError: java.nio.ByteBuffer.clear()Ljava/nio/ByteBuffer HOT 2
- java.lang.NoSuchMethodError: java.nio.ByteBuffer.clear()Ljava/nio/ByteBuffer; HOT 11
- Tests use "RAW" as algorithm for keys HOT 2
- Issue with leading 0's HOT 2
- Time step is not always honored HOT 2
- OTP Code validation problem
- Using a secret HOT 1
- project to gradle| Jar HOT 1
- Include validation functionality
- Handle NoSuchAlgorithmException exceptions for required algorithms HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from java-otp.