Dispatch seems to be slow compared to Java Executors


I recently had a look at how Swift is doing in the benchmark game compared to Java: https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/swift.html

It seems striking that in the three last benchmarks k-nucleotide, regex-redux, binary-trees the solution written in Swift is slower by a factor 4 till 7. This is striking as Swift in some benchmarks displayed there is performing sligtly better or a lot better than Java and for those three benchmarks it is eye-catching that they are implemented with multiple threads. The Java solution uses Java's Executors which is their thread pool implementation and Swift uses Grand Central Dispatch.

So at first sight it seems like Dispatch is a lot less efficient than Java's Executors. I wanted to ask whether Dispatch being relatively inefficient is a known issue and if so whether there are any plans to do something about it.

Also, I would like to ask whether there is some alternative to using Dispatch.

Cheers, Haddock

regex-redux is slow because the regex library being used is slow, not because of the thread pool. I haven't looked at the others, but I would guess it's similar.

You can use whatever C-compatible threading implementation you'd like though.

You are right with redeg-redux. I was too quick there in naming some culprit. When looking at binary-trees benmarck at the very bottom of that page regex seems not to be in the play.

Often, linked structures like binary trees and linked lists have had performance issues in Swift due to reference counting overhead applying to each node. As I said, I haven't looked at that benchmark, but that's a likely source of slowdowns for the binary-trees test at least.

Terms of Service

Privacy Policy

Cookie Policy