From harness-claude
Implements Flyweight pattern in JavaScript to share intrinsic state across thousands of similar objects, reducing memory usage at scale.
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeThis skill uses the workspace's default tool permissions.
> Share common state across many fine-grained objects to reduce memory usage
Implements GOF Flyweight pattern to share fine-grained objects and reduce memory by separating intrinsic and extrinsic state. Use for large numbers of similar objects like particles, UI elements, or map tiles.
Generates Flyweight pattern for PHP 8.4 to optimize memory usage by sharing intrinsic state across similar objects like icons or glyphs. Includes interface, factory, and unit tests.
Mandates invoking relevant skills via tools before any response in coding sessions. Covers access, priorities, and adaptations for Claude Code, Copilot CLI, Gemini CLI.
Share bugs, ideas, or general feedback.
Share common state across many fine-grained objects to reduce memory usage
FlyweightFactory with a Map to return cached instances.class BookFlyweight {
constructor(title, author) {
this.title = title; // intrinsic — shared
this.author = author; // intrinsic — shared
}
}
class BookFactory {
constructor() {
this._books = new Map();
}
getBook(title, author) {
const key = `${title}-${author}`;
if (!this._books.has(key)) {
this._books.set(key, new BookFlyweight(title, author));
}
return this._books.get(key);
}
}
const factory = new BookFactory();
const b1 = factory.getBook('JS Patterns', 'Stoyan');
const b2 = factory.getBook('JS Patterns', 'Stoyan');
console.log(b1 === b2); // true — same instance
The Flyweight pattern is a structural memory optimization. It trades CPU time (factory lookup) for memory savings by sharing object instances. JavaScript's garbage collector normally handles short-lived objects efficiently, so Flyweight is only necessary at extreme scale.
Trade-offs:
When NOT to use:
https://patterns.dev/javascript/flyweight-pattern