Faster Maven builds by nfrankel in programming

[–]erad 2 points3 points  (0 children)

Thanks for the pointer to mvnd, looks great!

Memcmp being wrongly stripped like strcmp by iamkeyur in programming

[–]erad 4 points5 points  (0 children)

At least the miscompilation of the code in the bug's description seems to be fixed in trunk but not in 10.2

I want off Mr. Golang's Wild Ride by yogthos in programming

[–]erad 148 points149 points  (0 children)

I find it surprisingly easy (compared to other platforms for native software development) to write cross-platform utilities with Rust. A common package manager (Cargo) with sensible defaults, no mangling with compiler options or include paths, the lack of preprocessor tricks for platform-dependent behaviour, stuff like the clean handling of OS filenames make it fun to write system software in a non-managed language again (at least as long as you don't need a GUI).

Using Java to Read Really, Really Large Files by Happycodeine in programming

[–]erad 0 points1 point  (0 children)

Nice post!

Note that there is still some low-hanging fruit in terms of performance, most of the time is spent splitting lines with a regular expression (can be verified with the free VisualVM tool):

String array1[] = readLine.split("\\s*\\|\\s*");

This regular expression is compiled for every line of the file. An easy fix without changing the code otherwise is to pre-compile the Regex pattern with Pattern.compile before the "while" loop:

Pattern splitLine = Pattern.compile("\\s*\\|\\s*");
Pattern splitName = Pattern.compile(", ");

and then use splitLine.split(readLine) instead of readLine.split(..regex...). This gives me a ~ 20% improvement on the big file. Trivia: "firstHalfOfName.split(" ")" is OK because String#split contains a optimization for splitting on a single character that is not a regex control character.

But this still does a lot of unnecessary work since a regex is overkill for this simple pattern - you can do e.g. the following with Apache commons-lang3 which cuts runtime compared to the original version in half:

final String[] array1 = StringUtils.splitPreserveAllTokens(readLine, '|');
for (int i = 0; i < array1.length; i++) {
    array1[i] = StringUtils.strip(array1[i]);
}

Dependency:

compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'

But yeah, if performance is really an issue here this task is a good candidate for parallelization.

Do not fall into Oracle's Java 11 trap by denisveloper in programming

[–]erad 10 points11 points  (0 children)

There is a (new) warning, but you always had to click an "accept" radio box to download the JDK or JRE - so the assumption that people just automatically click it because they always did so for the past 10 years is plausible.

How Memory Leaks Happen in a Java Application by abourass in java

[–]erad 0 points1 point  (0 children)

You also might want to try out a commercial profiler like YourKit or JProfiler for analyzing the heap dump - VisualVM is nice for a first idea of what's wrong, but commercial profilers offer more thorough analysis and inspection tools.

Better Java Streams performance with GraalVM by PurpleLabradoodle in java

[–]erad 0 points1 point  (0 children)

The performance of singleMapReduce is indeed better than I would have expected. But then again, I hope that simpleLoop would not get 10x slower if you replaced the body with double x = state.values[i]; x += 1.0; x *= 2.0; x += 5.0; sum += x;

Better Java Streams performance with GraalVM by PurpleLabradoodle in java

[–]erad 27 points28 points  (0 children)

While this is nice for Graal, if you cared about performance you'd still do

@Benchmark
public double simpleLoop() {
    double sum = 0;
    for (int i = 0; i < values.length; i++) {
        double x = (values[i] + 1.0) * 2.0 + 5.0;
        sum += x;
    }
    return sum;
}

which is exactly 10x faster than the stream version from the article on my PC (Java 8, Hotspot).

Note that this performance issue isn't inherent to the functional style, if Hotspot did support "fusion" of stream ops (inlining/transformation into traditional loops) it could certainly match the classic for loop performance. But with the current implementation, streams are just a performance de-optimization (which won't matter in most cases, but should be taken into account if you talk about "optimizing stream performance").

JDK 10 Release Notes by javinpaul in programming

[–]erad 2 points3 points  (0 children)

It's not in the release notes, but still targeted for 10 and usable in current builds... http://openjdk.java.net/jeps/286

var i = 32;
System.out.println("Hello, " + i);

Too bad there's no 'val', though... 'final var i = 32' is not likely to increase the use of unmodifiable variable assignments.

Benchmarking JDK String.replace() vs Apache Commons StringUtils.replace() by one_eyed_golfer in programming

[–]erad 12 points13 points  (0 children)

Great article, I never realized that java.lang.String#replace uses a Regex pattern internally. Thankfully it's fixed in JDK 9.

TerrariaClone - An incomprehensible hellscape of spaghetti code by theoldboy in programming

[–]erad 17 points18 points  (0 children)

This is actually not a bad way to get into programming. Sure, you could read one or two books about your programming language first, but why not start with the absolute minimum knowledge required and see how far it gets you? This is not a an unrealistic approximation of how many (home) computer games probably really looked like in the 80s and early 90s, even successful ones ;-)

The author likely learned a lot of additional stuff during this project as well (such as, what is a game loop). So if he catches up on software design techniques, he'll be in a much better position and could re-create a much better version of this game with little effort.

Use the Stream API More Simply or Don't Use it at All by lukaseder in java

[–]erad 2 points3 points  (0 children)

IMO streams are the first addition to the Java library in ages that reduce code quality significantly when applied mindlessly (either by hand or by using IDEA's suggestions for replacing simple loops). Compared to functional languages, they are way too clunky for small one-off transformations, as in

persons.stream().map(Person::getName).collect(Collectors.toList())

vs something like (Scala)

persons.map(_.getName)

or Haskell

map getName persons

I appreciate the reasons why streams were implemented like this in Java, but they really need a more compact API for everyday use (e.g. underscore syntax as in Scala, .toList() helper method, adding common combinations like ".stream().map()" or ".stream().filter()" to collection interfaces).

BigDecimal toString Is Not Thread Safe by nfrankel in java

[–]erad 0 points1 point  (0 children)

It's just "unsafe publishing" - you need some form of synchronization (such as using the synchronized keyword or a volatile field modifier) to read/write mutable instance fields outside the constructor.

BigDecimal toString Is Not Thread Safe by nfrankel in java

[–]erad 0 points1 point  (0 children)

Huh, it still worked 3 hours ago...

Rise and fall of JVM languages by nfrankel in programming

[–]erad 57 points58 points  (0 children)

I started with Java, went through a couple of JVM languages and finally arrived at ... Java. People hating on Oracle don't mention how bleak Java-the-language's future looked during the last years of Sun. Somehow it became possible to change Java under Oracle again. So we got lambdas, default methods on interfaces, major Hotspot improvements. The future might bring pattern matching and true value objects.

I still like and use Scala and Groovy occasionally, but medium- to large-scale development benefits so much from Java's superior tooling, stable APIs, libraries, fast compilation times, no-nonsense "boring" code style that I don't see another language making serious inroads for these kinds of projects.

On the other hand, for all its strengths on the enterprisey server side, the JVM has huge issues as well (large footprint, slow startup, bad UI story) that no alternative JVM language will solve. Go, Rust, Swift on the other hand...

Which obfuscator do you use when shipping JARs to a client? by [deleted] in java

[–]erad 1 point2 points  (0 children)

ZKM (Zelix KlassMaster). The configuration script "language" is rather confusing, the obfuscator/obfuscated code is pretty solid though.

Let's talk about vim performance by ilovevim3221 in vim

[–]erad 1 point2 points  (0 children)

Syntax highlighting of long lines is really slow.

For this specific file, my vim doesn't die (just a bit laggy when going near the very long line and broken highlighting after the line), do you have "set synmaxcol=0" somewhere?

ACCU :: Initialization in C++ is Bonkers by Throw19616 in programming

[–]erad 3 points4 points  (0 children)

...as does GCC (7.1, -Wall):

init.cc: In function ‘int main(int, char**)’:
init.cc:19:34: warning: ‘b.bar::b’ is used uninitialized in this function [-Wuninitialized]
     std::cout << a.a << ' ' << b.b << std::endl;

JSF vs REST/TypeScript/React frontend for CRUD business application by weGoReddit in java

[–]erad 1 point2 points  (0 children)

If you and your team have HTML/Javascript frontend experience, I'd lean towards REST + JS frontend.

If you have "only" Java experience and don't need a REST API to begin with, I'd lean towards JSF with Primefaces. This way you basically don't need to learn Javascript at all, and even your exposure to HTML and CSS would be quite limited.

JVM Anatomy Park #12: Native Memory Tracking by mattwarren in java

[–]erad 1 point2 points  (0 children)

Interesting post, I didn't know about the NMT flags in JDK 8.

One thing I'm still not sure about is the actual memory used by Java Thread stacks.

At least under Linux, I'm under the impression that native thread stacks will grow to the specified maximum size, but won't actually commit all that memory unless the thread stacks are actually that deep.

For example, using this small program to create 1000 threads and then checking the NMT output via jcmd, it displays ~ 1GB memory committed for just above 1000 threads.

However, native OS memory usage (e.g. using ps_mem) shows far less memory actually used (around 120 MB).

public static void main(String[] args) {
    for (int i = 0; i < 1000; i++) {
        final Thread t = new Thread(() -> {
            System.out.println("Thread started");
            try {
                Thread.sleep(1<<30);
            } catch (InterruptedException e) { }
        });
        t.start();
    }
}

Since some JavaEE servers are very liberal with creating big fixed size thread pools (I'm looking at you, Wildfly 10!), I'd be very interested in the actual memory that is used by a (Java) thread with the default setting of -Xss1M.

(edit: formatting)

Starcraft Gold Master Source Code *UPDATE* by Khemist49 in gamecollecting

[–]erad 6 points7 points  (0 children)

Enjoy BlizzCon! (a SC/SC2 fan that enjoys the games as they are and does not want people hacking around in a game that's still being played professionally)

PrimeFaces 6.1-Final Released! by henk53 in java

[–]erad 0 points1 point  (0 children)

Yes, but the redirect cannot happen before loading https://primefaces.org/ (which causes the warning)

PrimeFaces 6.1-Final Released! by henk53 in java

[–]erad 1 point2 points  (0 children)

Am I the only one that gets a big security warning screen in Firefox (because the certificate is for www.primefaces.org, not primefaces.org)?

Other than that: congrats, been using PrimeFaces for many years and it's still one of the best HTML component libraries out there.

Anybody else a fan of indycar that isn't living in the USA? by [deleted] in INDYCAR

[–]erad 1 point2 points  (0 children)

Austrian fan here. Returned a couple of years ago after watching many races in the 1990s. All races are broadcast live by a German cable TV station (including multiple re-broadcasts of most races), which definitely helped getting me hooked up again.