Skip to content

Instantly share code, notes, and snippets.

View jdmichaud's full-sized avatar

jdmichaud

View GitHub Profile
@jdmichaud
jdmichaud / Speculation in JavascriptCore.md
Created September 5, 2020 14:03
Speculation in JavascriptCore

Optimizing javascript through speculative execution is to speculate on type and produce optimizations based on those speculation.

Profiling is the act of speculating and will allow you to optimize JS execution better.

There are various ways of doing that. You can speculate on the type of variables on each appearance and then chose a path to an optimized code for that type of the slow path if the speculation fails (diamond speculation). The technique used by JavaSciptCore is OSR (On Stack Replacement). It will speculate and definitly exit a optimized path on failing. Exiting is fast and easy, reentry to the optimized path is slow and hard.

JavaScriptCore (the Safari JS VM) has a 4 tier interpreter/compiler infrastructure. JavaScriptCore (JSC) first compile the javascript into the VM bytecode. Then this bytecode get interpreted by LLint (Low Level Interpreter) which does not perfom optimization, just execute and profile the code for the next tier. The next tier is the basline JIT which will convert the bytec

@jdmichaud
jdmichaud / lexer.rs
Created September 19, 2020 17:36
A simple tokenizer in rust
// rustc lexer.rs && curl -s https://norvig.com/big.txt | ./lexer
use std::io::{Read, Result, stdin};
#[derive(Debug)]
struct Token<'a> {
s: &'a str,
start_index: usize,
}
@jdmichaud
jdmichaud / lexer.rs
Created December 2, 2020 11:40
Tokenize a text file through a Iterator
// rustc lexer.rs && curl -s https://norvig.com/big.txt | ./lexer
use std::io::{Read, Result, stdin};
#[derive(Debug)]
struct Token<'a> {
s: &'a str,
start_index: usize,
}
On a Ubuntu 19.04
## Install the necessary package:
```
sudo apt-get install \
qemu-kvm \
libvirt-daemon-system \
libvirt-clients \
bridge-utils \
libosinfo-bin \
libguestfs-tools
@jdmichaud
jdmichaud / rust-observable.rs
Created April 29, 2021 19:54
Rust Observables
use Obsevable;
use Observer;
fn main() {
let observable = new Observable<u8>(|observer: &mut Observer<u8>| {
observer.next(255);
observer.complete();
});
let subscription1 = observable.subscribe({
@jdmichaud
jdmichaud / extract.sh
Created May 2, 2021 15:15
Extract Wikipedia dumps
#!/bin/bash
# First download the page listing all the dumps, then extract, with some brittle xpath magic the list of dump files and curl them locally.
curl -sL https://dumps.wikimedia.org/commonswiki/20210420/ | \
xidel --xpath '//li[./span[contains(@class, "title") and ./big/b/text() = "Articles, templates, media/file descriptions, and primary meta-pages."]]/ul/li/a/@href' - | \
xargs -n 1 -i curl --progress-bar -OL -C - https://dumps.wikimedia.org/{}
@jdmichaud
jdmichaud / vim-cheatsheet.md
Last active May 4, 2025 06:20
My VIM stuff

Vim grammar

Reload configuration after change: :so $MYVIMRC

navigate:

  • hjkl: <v^>
  • w: advance to beginning of next word
  • b: rewind to beginning of next word
  • e: advance to end of next word
  • Ctrl-o: exit INSERT mode for one and only one command, then get back at it
@jdmichaud
jdmichaud / jours_feries.py
Created June 2, 2021 18:46
Compute the number of jours feries between 2000 and 2030 in France
from functools import reduce
from datetime import datetime
from jours_feries_france import JoursFeries
def computeJoursFeries(year):
return reduce(
lambda acc, day: acc + 1 if day.isoweekday() != 6 and day.isoweekday() != 7 else acc,
JoursFeries.for_year(year).values(),
0,
)
@jdmichaud
jdmichaud / ts-chain.txt
Created June 9, 2021 13:36
Typescript compilation chain
Source ─(scanner)─► Tokens ─(parser)─► AST ─(binder)─► Symbol ─(checker)──(emitter)─► JS
│ ▲ ▲
╰──────────────────────────╯──────────╯
@jdmichaud
jdmichaud / RustCheatSheet.pdf
Last active January 24, 2024 19:27
Rust Smart Pointer (Cell, RefCell, Rc)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.