Thread pools on the JVM should usually be divided into the following three categories:
- CPU-bound
- Blocking IO
- Non-blocking IO polling
Each of these categories has a different optimal configuration and usage pattern.
I was talking to a coworker recently about general techniques that almost always form the core of any effort to write very fast, down-to-the-metal hot path code on the JVM, and they pointed out that there really isn't a particularly good place to go for this information. It occurred to me that, really, I had more or less picked up all of it by word of mouth and experience, and there just aren't any good reference sources on the topic. So… here's my word of mouth.
This is by no means a comprehensive gist. It's also important to understand that the techniques that I outline in here are not 100% absolute either. Performance on the JVM is an incredibly complicated subject, and while there are rules that almost always hold true, the "almost" remains very salient. Also, for many or even most applications, there will be other techniques that I'm not mentioning which will have a greater impact. JMH, Java Flight Recorder, and a good profiler are your very best friend! Mea
trait SList[T] { | |
def ::[H](head: H): ::[H, T] = new ::(head, this) | |
} | |
type SNil = Nothing | |
case object SNil extends SList[SNil] | |
case class ::[H, T](head: H, tail: SList[T]) extends SList[H :: T] { | |
override def toString = s"$head :: $tail" | |
} | |
println( |
import scala.util.Random | |
// Simple example of an IO effect Monad, no Cats | |
object MyIO extends App{ | |
// IO encapsulates a side effecting operation | |
final class IO[A](val run: () => A) { | |
def map[B](f: A => B): IO[B] = IO(f(run())) |
# Windows 10 raylib mingw CMakeLists.txt for building any raylib example from the link below | |
# https://www.raylib.com/examples.html | |
cmake_minimum_required(VERSION 3.16) | |
project(untitled C) | |
set(CMAKE_C_STANDARD 11) | |
set(CMAKE_LIBRARY_PATH "C:\\raylib\\mingw\\i686-w64-mingw32\\lib") | |
include_directories(C:\\raylib\\mingw\\i686-w64-mingw32\\include) |
{ | |
trait QList[+A]{ | |
def ::[B >: A](head: B): QList[B] = new ::(head, this) | |
} | |
case class ::[+A](head: A, tail: QList[A]) extends QList[A] | |
object QNil extends QList[Nothing] |
<div class="wrapper"> | |
<h1>Header</h1> | |
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Perspiciatis officiis sit veniam recusandae labore numquam ipsum iusto minima voluptatem voluptas. Consequatur officiis ipsa molestias laborum dicta eaque maxime quam quas, reiciendis, officia ut? Necessitatibus, exercitationem vel sit magni totam eos nisi asperiores ipsam molestias libero beatae. Quaerat provident ipsa culpa saepe, voluptas assumenda blanditiis maxime nesciunt quas non dolores sit dignissimos placeat eum reprehenderit corrupti nisi. Veniam iure et dicta sapiente ducimus repudiandae voluptatum cupiditate officia tempora. Repellat officia cupiditate pariatur blanditiis cum? Recusandae veniam ullam sint expedita perspiciatis eum, maxime quasi laborum modi iusto vitae eveniet illo odio aliquam deserunt totam molestias blanditiis voluptatem exercitationem amet fuga enim dolorum numquam. Ea accusamus quaerat expedita dolore, impedit similique cupiditate, corporis, aliquam deserunt necessitatibus qu |
implicit class ThrowableWithRootCause(throwable: Throwable) { | |
def rootCause: Throwable = cause(throwable) | |
private def cause(t: Throwable): Throwable = t.getCause match { | |
case null => t | |
case _ => cause(t.getCause) | |
} | |
} |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.