Skip to content

Instantly share code, notes, and snippets.

View anuragsoni's full-sized avatar

Anurag Soni anuragsoni

View GitHub Profile

Quick Tips for Fast Code on the JVM

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

Thread Pools

Thread pools on the JVM should usually be divided into the following three categories:

  1. CPU-bound
  2. Blocking IO
  3. Non-blocking IO polling

Each of these categories has a different optimal configuration and usage pattern.

@Stwissel
Stwissel / AsyncInputStream.java
Last active April 17, 2024 14:12
Wrapping an InputStream into a ReadStream<Buffer> for vert.x
# ==========================================================================
# Copyright (C) 2017-2024 NotesSensei ( https://www.wissel.net/ )
# All rights reserved.
# ==========================================================================
# Licensed under the Apache License, Version 2.0 (the "License"). You may
# not use this file except in compliance with the License. You may obtain a
# copy of the License at <http://www.apache.org/licenses/LICENSE-2.0>.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
@Gankra
Gankra / gist:155234908dae0d984fe5
Created March 19, 2015 20:56
mutable singly-linked list
struct List<T> {
head: Option<Box<Node<T>>>
}
struct Node<T> {
elem: T,
next: Option<Box<Node<T>>>,
}
impl<T> List<T> {
@finalfantasia
finalfantasia / fixing_text_anti_aliasing_in_fedora.md
Last active March 20, 2024 22:53
Fixing Text Anti-aliasing in Fedora
  1. Add the RPMFusion repositories (both free and non-free) to the YUM repository directory (/etc/yum.repos.d/):
sudo dnf localinstall --nogpgcheck http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
  1. Install the patched version of FreeType with subpixel rendering enabled:
sudo dnf install -y freetype-freeworld