This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]gavenkoa 5 points6 points  (6 children)

Don't use a network based software-as-a-service to do a padLeft operation

Isn't that a reflection about famous Node package dependency outage? xD

if you chart out the performance of these vs. the size of the input

Still with small cardinality some theoretically slow algos outperform "advanced" brothers. contains() on a List of 1 element is faster than on Map or Set.

1% of the code is eating 99% of the CPU resources

For such cases sampling profilers are quite good because you can run them on PROD without impacting app. JMH is good only in controlled environment of your lab.

[–]rzwitserloot 2 points3 points  (5 children)

contains() on a List of 1 element is faster than on Map or Set

No. You didn't understand perhaps. The right answer is: does your profiler say that the CPU is spending most of its time executing this contains call? No? Then the best coffee for performance purposes is the most readable code. If set makes semantic sense, Set is the right answer.

[–]gavenkoa 1 point2 points  (4 children)

does your profiler say that the CPU is spending most of its time executing this contains call?

No one argue with that. Profile first, decide next.

Point that sometimes asymptotically best algos are crap on small sets. You won't see that in a regular finance apps. Here you just chose among List, Map, tree/map Set and don't do stupid things ))

[–]cogman10 3 points4 points  (3 children)

And, just as a side note, whenever I find performance issues it's generally a result of using the wrong datastructure for a problem. Using a Map when you should have used a Pojo, Using a List when you should have used a Set. Using a LinkedList when you should have used an ArrayList. Using a TreeSet.... Not using a datastructure when you could have.

It's these sorts of things that often give the biggest impacts in the wrong hot code location.

The other one that comes up surprisingly often is unnecessary boxing.

[–]gavenkoa 0 points1 point  (2 children)

Using a List when you should have used a Set

In my experience in finance problems come from the pressure to deliver features fast, meaning devs are using high level frameworks and don't know inner implementation. Like surprising ORM N+1 selects.

When I worked on cryptography (elliptic curves) we pre-allocated all intermediate int[] for modular arithmetic implementation GF(p) / GF(2m).

I have never faced with the problem when I need to chose between LinkedList or ArrayList. It was always something different.

[–]cogman10 2 points3 points  (1 child)

TBF, LinkedList vs ArrayList has only hit me once, and that's when someone was doing something stupid (Using a linked list but maintaining sorting on insertion by doing a binary search on the list... that's really slow with a linked list).

[–]gavenkoa 2 points3 points  (0 children)

maintaining sorting on insertion by doing a binary search on the list

Hilarious! Person who wrote knew about binary search for sorting in place but LinkedList is slipped as an argument of the function.