yeux v5.10.7
Yeux
Yeux improves the performance of applications that create many light-weight and short-lived objects.
import { yeux } from 'yeux'
interface Player {
name: string | undefined
x: number
y: number
}
interface PlayerInitial extends Player {
name: undefined
x: 0
y: 0
}
const pool = yeux<Player, PlayerInitial>(
() => ({
name: undefined,
x: 0,
y: 0
}),
obj => {
obj.x = 0
obj.y = 0
obj.name = undefined
return obj as PlayerInitial
}
)
const A = pool.get()
const B = pool.get()
pool.pool(A, B)
const C = pool.get()
const D = pool.get()
A === C // true
B === D // trueAPI
yeux
yeux function takes two arguments and two type arguments and returns the pool, get, and isActive methods. The first type argument is the wider object type (Player in the example). The second type argument is a narrowed down, initial object type (PlayerInitial in the example). The first argument is an object factory function, and the second argument is a reset function.
get
get function returns an object from a pool, or if the pool is empty calls the factory function and returns the object. The objects returned by the factory function are not placed in the pool so that they can be disposed of by the garbage collector.
pool
Objects are placed back in the pool with the pool function. Objects not placed back in the pool are disposed of by the garbage collector no references to them exist.
isPooled
The isPooled function receives an object as an argument and returns true if the object is present in the pool, and returns false if the object is not present.
License
MPL-2.0
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago