Skip to content

Instantly share code, notes, and snippets.

View bluwy's full-sized avatar
♥️
【=◈︿◈=】

Bjorn Lu bluwy

♥️
【=◈︿◈=】
View GitHub Profile
@bluwy
bluwy / _readme.md
Last active January 3, 2025 11:36
Benchmark the time spent on transferring data in child process

Copy the file s and run node main.js. There's some numbers you can tweak at the top of the file imitating a project with some modules and average module file size.

It may take a while to run. Line 29 shows the time a took between a stdin write and stdout read for each request made.

@bluwy
bluwy / _results
Last active January 1, 2025 14:51
Performance between using node Buffer vs ArrayBuffer to parse tar files
┌─────────┬──────────────────────┬──────────────────────┬─────────────────────┬────────────────────────────┬───────────────────────────┬─────────┐
│ (index) │ Task name │ Latency average (ns) │ Latency median (ns) │ Throughput average (ops/s) │ Throughput median (ops/s) │ Samples │
├─────────┼──────────────────────┼──────────────────────┼─────────────────────┼────────────────────────────┼───────────────────────────┼─────────┤
│ 0 │ 'buffer' │ '53789.86 ± 0.14%' │ '52708.03' │ '18746 ± 0.06%' │ '18972' │ 37182 │
│ 1 │ 'array buffer' │ '39104.97 ± 0.74%' │ '36292.02' │ '26764 ± 0.08%' │ '27554' │ 51145 │
│ 2 │ 'array buffer extra' │ '37756.63 ± 0.25%' │ '36250.00' │ '27002 ± 0.07%' │ '27586' │ 52971 │
└─────────┴──────────────────────┴──────────────────────┴─────────────────────┴────────────────────────────┴───────────────────────────┴──────
@bluwy
bluwy / _results
Last active January 1, 2025 08:44
zlib.gunzip vs DecompressionStream performance benchmark
┌─────────┬───────────────────────────────────────────┬──────────────────────┬─────────────────────┬────────────────────────────┬───────────────────────────┬─────────┐
│ (index) │ Task name │ Latency average (ns) │ Latency median (ns) │ Throughput average (ops/s) │ Throughput median (ops/s) │ Samples │
├─────────┼───────────────────────────────────────────┼──────────────────────┼─────────────────────┼────────────────────────────┼───────────────────────────┼─────────┤
│ 0 │ 'zlib gunzip (from node buffer)' │ '1921050.70 ± 3.04%' │ '1751584.05' │ '550 ± 1.31%' │ '571' │ 521 │
│ 1 │ 'DecompressionStream (from array buffer)' │ '2922942.41 ± 4.29%' │ '2149625.00' │ '392 ± 3.36%' │ '465' │ 343 │
│ 2 │ 'DecompressionStream (from stream)' │ '2904491.21 ± 4.31%' │ '2123957.99' │ '395 ± 3.37%' │ '471' │ 345 │
└─────────┴─────
@bluwy
bluwy / GitHub Delete Issues.user.js
Last active May 23, 2024 09:32
Userscript to add a delete issue button in the issues page. It opens the issue in a new tab, delete it, and auto-close the tab (sometimes not working). There's also a button to delete all issues in the current page, which opens all the tabs at once. Also works for discussions. BEWARE that deleting issues is not reversible!
// ==UserScript==
// @name GitHub Delete Issues
// @license MIT
// @version 0.1.0
// @description Adds buttons to easily delete issues
// @author bluwy
// @match https://github.com/**
// @grant none
// ==/UserScript==
@bluwy
bluwy / publint_analysis.json
Last active March 16, 2025 04:17
Results of publint's analysis script (force push only)
@bluwy
bluwy / rollup-optimization-research.md
Last active March 6, 2025 10:43
Rollup build optimization research

Rollup build optimization research

Rollup builds doesn't scale well in large apps. You need to increase Node's memory with --max-old-space-size=4096 to handle all the modules. This is one of Vite's highest-rated issue.

This file documents various findings and attempts to improve this issue.

How Rollup works

NOTE: I've only been reading Rollup's source code for a while, so some of these may not be accurate.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bluwy
bluwy / sequence.js
Last active March 29, 2022 03:42
Run Svelte preprocessors in the sequence they are declared
import { preprocess } from 'svelte/compiler'
/**
* @typedef {import("svelte/types/compiler/preprocess").PreprocessorGroup} PreprocessorGroup
* @param {PreprocessorGroup[]} preprocessors
* @returns {PreprocessorGroup[]}
*/
export function sequence(preprocessors) {
return preprocessors.map((preprocessor) => ({
markup({ content, filename }) {
@bluwy
bluwy / reloadImgOnFail.js
Created July 10, 2021 12:48
[Svelte] Reload image on fail to fetch
export function reloadImgOnFail(img, opts = {}) {
opts = ensureOpts(opts)
let retryCount = 0
function handleError() {
if (retryCount >= opts.maxRetryCount) {
if (opts.fallbackSrc && img.src !== opts.fallbackSrc) {
img.src = opts.fallbackSrc
}
@bluwy
bluwy / svelte-preprocess-svg.js
Last active May 30, 2021 07:15
Load SVGs as Svelte components with the least runtime overhead. Not sure if this actually improve performance?
export default function sveltePreprocessSvg() {
return {
markup({ content }) {
content = content.trim()
if (content.startsWith('<svg ') && content.endsWith('</svg>')) {
return { code: `{@html \`${content}\`}` }
} else {
return { code: content }
}
},