Skip to content

Instantly share code, notes, and snippets.

View AugustNagro's full-sized avatar

August Nagro AugustNagro

View GitHub Profile

Hey guys, I've had some time to think about both aproaches Jotschi and I are pursuing and have come to this conclusion:

Each approach has flaws but combined can be something really special. First, I made a list of the the pros/cons.

Async-Await: In this approach, when async(X) is called, we offload X to a virtual thread that executes on the same event-loop (platform) thread.

Pros:

  • Works with the existing netty event-loop on platform threads.
  • Since await returns Future, it can be integrated into existing Vertx codebases incrementally.
  • You can call any plain blocking library within async() without blocking the event loop threads
import io.vertx.core.Future;
import io.vertx.core.Promise;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Function;
public class VertxLoomNew {
List<String> evens = someList.stream()
  .filter(i -> i % 2 == 0)
  .toList()

For-comprehension Version:

ArrayList evens = for (int i : myArrayOrIterable) {
class Prop {
constructor(writer, listeners) {
this.writer = writer;
this.listeners = listeners;
}
}
class PropReader {
constructor(name, changeListener, props) {
this._name = name;
import org.openjdk.jmh.annotations.*;
import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.CountedCompleter;
import java.util.concurrent.ExecutionException;
/**
* 40 Core Xeon E5-2660 v3 @ 2.60GHz
*
@AugustNagro
AugustNagro / Converter.java
Created November 9, 2019 21:26
Convert output of -XX:PrintTouchedMethodsAtExit into form usable by JEP 295 AOT
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.stream.Stream;
/**
* Converts from TouchedMethods format to AOT format
*
Clang options
my cpu: https://ark.intel.com/content/www/us/en/ark/products/84985/intel-core-i5-5257u-processor-3m-cache-up-to-3-10-ghz.html
(also try O2)
-O3 enable best optimizations
-march=native compile for arch, not isa
-mtune=broadwell not sure if same in clang as gcc (https://lemire.me/blog/2018/07/25/it-is-more-complicated-than-i-thought-mtune-march-in-gcc/)
-pipe use pipes between commands, when possible
@AugustNagro
AugustNagro / Utf8CharSeq.java
Created October 26, 2019 07:11
Pattern match a UTF-8 ByteBuffer in Java
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
public class Utf8CharSeq implements CharSequence {
private final ByteBuffer b;
public Utf8CharSeq(ByteBuffer b) {
this.b = b;
}
@AugustNagro
AugustNagro / Main.java
Created October 4, 2019 01:26
LEG V8 <=> BINARY... easy!
import java.util.Map;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static java.lang.Integer.valueOf;
import static java.util.Map.entry;
public class Main {
public static interface ReadOnlySpliterator {
int characteristics();
long estimateSize();
long getExactSizeIfKnown();
boolean hasCharacteristics(int characteristics);
}