-
Pre-allocate Slices with Known Capacity When the eventual size of a slice is known, pre-allocating with
make([]T, 0, capacity)
creates the underlying array a single time. This critical practice avoids multiple, inefficient reallocations and the expensive process of copying all existing elements to a new, larger array as youappend
data. -
Use the
arena
Package for Short-Lived Objects New in recent Go versions, thearena
package provides a safe way to allocate memory that can be freed all at once. This is perfect for functions that create many temporary objects (like during a single request), as it can nearly eliminate GC pressure from that workload.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
public class For { | |
static final int SIZE = 1_000_000; | |
public static void main(String[] args) { | |
int[] data = new int[SIZE]; | |
Random rnd = new Random(42); | |
for (int i = 0; i < SIZE; i++) data[i] = rnd.nextInt(1000) - 500; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#include <math.h> | |
// REQUIRED for the M1/Apple Silicon native BLAS implementation (Accelerate Framework) | |
// gcc -O3 -Wall -Wextra Matmul.c -o Matmul -lm -framework Accelerate | |
#include "cblas.h" | |
// --- Utility Functions --- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// @file A high-performance buffer pool implementation in Dart for managing TypedData. | |
/// @author Piyush Katariya | |
/// @version 1.5.0 | |
library buffer_pool; | |
import 'dart:typed_data'; | |
import 'dart:math'; | |
import 'dart:ffi'; | |
import 'package:ffi/ffi.dart'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// benchmark.js | |
import { faker } from '@faker-js/faker'; | |
import fs from 'fs'; | |
import crypto from 'crypto'; | |
// Text encoder/decoder for binary operations | |
const textEncoder = new TextEncoder(); | |
const textDecoder = new TextDecoder(); | |
// Mock MessageType enum |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _GNU_SOURCE | |
#include "bufferpool.h" | |
#include <stdlib.h> | |
#include <string.h> | |
#include <pthread.h> | |
#include <stdatomic.h> | |
#include <dlfcn.h> | |
#include <errno.h> | |
#include <sys/mman.h> | |
#include <inttypes.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
process.title = 'http2server'; | |
console.error('SERVER PID', process.pid); | |
/* ---------- Linux early tuning ------------------------------ */ | |
if (process.platform === 'linux') { | |
try { | |
require('fs').writeFileSync('/proc/sys/net/core/somaxconn', '65535'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:typed_data'; | |
import 'dart:math'; | |
// SIMD-optimized big integer operations using Float32x4 and Int32x4 | |
class SIMDBigInt { | |
static final _rng = Random.secure(); | |
// Convert regular int to SIMD-friendly chunks | |
static Float32x4List toFloat32x4List(List<int> values) { | |
final padded = List<int>.from(values); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
// --- CORE TYPES --- | |
// Entity is a unique identifier. | |
type Entity uint32 | |
// ComponentType is the identifier for a component type, used for bitmasking. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class LRUCache<K, V> { | |
private readonly keys: K[]; | |
private readonly values: V[]; | |
private readonly accessOrder: number[]; // Index-based linked list | |
private readonly keyToIndex = new Map<K, number>(); | |
private readonly maxSize: number; | |
private head = 0; | |
private tail = 0; | |
private size = 0; |
NewerOlder