3 ms·
Yeah a millisecond is a long time even in Java. Couple of years I was writing a java backend server for caching+computation. I was severely memory strapped and
by tmd83 11y ago
Yeah a millisecond is a long time even in Java. Couple of years I was writing a java backend server for caching+computation. I was severely memory strapped and was designing the daily expiration of data. The core data structure was map<map>. Now the keys that I had for expiration was in the 2nd level and I was troubled for the memory usage for a kind of secondary index for fast expiry plus the complexity of managing it. At the end I said what the heck and just did a full iteration of the 2nd level map and doing a hash lookup on the expired key, kind of reversing the logic (its essentially what a DB hash join does). I don't remember if I did a hashmap benchmark first or not. Essentially in my very old desktop (compared to current machine) I was doing 0.5M hashlook (2 lookups actually) per second per core and the rest was a very successful history.
So I think yeah with layers upon layers of libraries we tend to forget how fast a computer is and thats often sad. The whole misconception of premature optimisation has some incorrect side affect, people often ignore performance when designing things. The core parts of most designs specially library or shared infrastructure code should have some concepts of overhead/cost even though this shouldn't be overblown. Unconsciously bad designs then are often followed by super efficient but complicated algorithm to fix the design inefficiency.
One thing I very much agree with the blog post. The more conscious you become of these things the more you can guess where a bottleneck exists or where you should take care. You wouldn't always be right and you should always benchmark specially if it's critical enough or you are changing design too much for performance. But a general awareness can be very helpful.
As I completely rewrote that backend server few months ago I started with a very simple design, data structure and simple algorithms (linear scanning with a bit of indexing through plain java hashmap/concurrentashmap) it worked flawlessly the first time (in terms of performance). It is serving over a million request per day of fairly complicated dashboard generation at ~0ms latency and 2 YGC/hr I think. Some might call it premature optimisation but I think you need to have an understanding of where performance is critical and design for that. That doesn't mean you should think everything is performance critical and start optimising every line of your code.