4 ms·
> I simply cannot believe that just avoiding object initialization or state would add up to a meaningful difference. Depends in how tight a loop you do it. If
by ajuc 5y ago
> I simply cannot believe that just avoiding object initialization or state would add up to a meaningful difference.
Depends in how tight a loop you do it. If you do a lot of stuff and once in a blue moon you do this - fine.
If you create and destroy objects every time you do basic operation that most of your code consists of - you'll be several times slower.
In my current job we are required to do this:
Optional.of(user).ifPresent(this::doSomethingWithUser);
instead of this:
if (user != null) {
doSomethingWithUser(user);
}
The code is very simple and mostly consist of taking json, parsing it, checking a few fields and modifying them, and calling another service with another format of json.
Most of what we do is these null checks disguised as opionals.
And then people complain performance got worse compared to mainframe assembler.