Skip to content

Commit c3903b4

Browse files
committed
Merge branch 'master' of github.com:poolifier/poolifier-web-worker
2 parents ebe0b7e + bb4bfe5 commit c3903b4

34 files changed

+742
-132
lines changed

.github/copilot-instructions.md

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# Copilot Instructions (repository-wide, language-agnostic)
2+
3+
These instructions guide GitHub Copilot to generate changes consistent with this
4+
repository's conventions, regardless of programming language.
5+
6+
## Glossary
7+
8+
- **Tunables**: user-adjustable parameters that shape behavior, exposed via
9+
options or configuration files.
10+
- **Canonical defaults**: the single, authoritative definition of all tunables
11+
and their defaults.
12+
13+
## Implementation guidance for Copilot
14+
15+
- **Before coding**:
16+
- Perform a comprehensive inventory of the codebase. Search for and read:
17+
- README.md, CONTRIBUTING.md, and all other documentation files.
18+
- code files related to the task.
19+
- Identify existing code architecture, design patterns, canonical defaults,
20+
naming patterns and coding styles.
21+
- **When coding**:
22+
- Follow the core principles and TypeScript/Node.js conventions below.
23+
- Follow identified design patterns, naming patterns and coding styles.
24+
- **After coding**:
25+
- Ensure changes pass quality gates below.
26+
- **When adding a tunable**:
27+
- Add to canonical defaults with safe value.
28+
- Ensure the options and configuration section below is respected.
29+
- Update documentation and serialization.
30+
- **When implementing analytical methods**:
31+
- Follow statistical conventions below.
32+
- **When refactoring**:
33+
- Keep public APIs stable; provide aliases if renaming unless explicitly
34+
requested.
35+
- Update code, tests, and documentation atomically.
36+
- **When documenting**:
37+
- Follow documentation conventions below.
38+
39+
## Core principles
40+
41+
- **Design patterns**: prefer established patterns (e.g., factory, singleton,
42+
strategy) for code organization and extensibility.
43+
- **Algorithmic**: prefer algorithms or heuristics solving the problem while
44+
minimizing time and space complexity.
45+
- **DRY**: avoid duplication of logic, data, and naming. Factor out
46+
commonalities.
47+
- **Single source of truth**: maintain a canonical defaults map for
48+
configuration tunables. Derive all user-facing options automatically.
49+
- **Naming coherence**: prefer semantically accurate names across code,
50+
documentation, directories, and outputs. Avoid synonyms that create ambiguity.
51+
- **English-only**: code, tests, logs, comments, and documentation must be in
52+
English.
53+
- **Small, verifiable changes**: prefer minimal diffs that keep public behavior
54+
stable unless explicitly requested.
55+
- **Tests-first mindset**: add or update minimal tests before refactoring or
56+
feature changes.
57+
- **Documentation standards**: must follow established standards for programming
58+
languages.
59+
60+
## Options and configuration
61+
62+
- **Dynamic generation**: derive CLI and configuration options automatically
63+
from canonical defaults. Avoid manual duplication.
64+
- **Merge precedence**: defaults < user options < explicit overrides (highest
65+
precedence). Never silently drop user-provided values.
66+
- **Validation**: enforce constraints (choices, ranges, types) at the option
67+
layer with explicit typing.
68+
- **Help text**: provide concrete examples for complex options, especially
69+
override mechanisms.
70+
71+
## Statistical conventions
72+
73+
- **Hypothesis testing**: use a single test statistic (e.g., t-test) when
74+
possible.
75+
- **Divergence metrics**: document direction explicitly (e.g., KL(A||B) vs
76+
KL(B||A)); normalize distributions; add numerical stability measures.
77+
- **Effect sizes**: report alongside test statistics and p-values; use standard
78+
formulas; document directional interpretation.
79+
- **Distribution comparisons**: use multiple complementary metrics (parametric
80+
and non-parametric).
81+
- **Multiple testing**: document corrections or acknowledge their absence.
82+
83+
## Reporting conventions
84+
85+
- **Structure**: start with run configuration, then stable section order for
86+
comparability.
87+
- **Format**: use structured formats (e.g., tables) for metrics; avoid free-form
88+
text for data.
89+
- **Interpretation**: include threshold guidelines; avoid overclaiming
90+
certainty.
91+
- **Artifacts**: timestamp outputs; include configuration metadata.
92+
93+
## Documentation conventions
94+
95+
- **Clarity**: plain, unambiguous language; avoid marketing jargon and
96+
speculation.
97+
- **Concision**: remove boilerplate; state facts directly without redundant
98+
phrasing.
99+
- **Structure**: use consistent section ordering; follow stable patterns for
100+
comparable content.
101+
- **Timeliness**: document current state; exclude historical evolution (except
102+
brief API breaking change notes).
103+
- **Terminology**: use correct and consistent terminology; distinguish clearly
104+
between related concepts.
105+
- **Exhaustivity**: cover all user-facing behavior and constraints; omit
106+
internal implementation details unless necessary for usage.
107+
- **Pertinence**: include information that aids understanding or usage; remove
108+
tangential content.
109+
- **No duplication**: maintain single authoritative documentation source;
110+
reference other sources rather than copying.
111+
112+
Documentation serves as an operational specification, not narrative prose.
113+
114+
## TypeScript conventions
115+
116+
- **Naming**: Use camelCase for variables/functions/methods, PascalCase for
117+
classes/types/enums/interfaces.
118+
- **Async operations**: Prefer async/await over raw Promises; handle rejections
119+
explicitly with try/catch.
120+
- **Error handling**: Use typed errors with structured properties when
121+
applicable.
122+
- **Worker communication**: Use broadcast channels for decoupled worker<->main
123+
thread messaging.
124+
- **Null safety**: Avoid non-null assertions (!); use optional chaining (?.) and
125+
nullish coalescing (??).
126+
- **Type safety**: Prefer explicit types over any; use type guards and
127+
discriminated unions where appropriate.
128+
- **Promise patterns**: Return Promises from async operations; store
129+
resolvers/rejectors in Maps for request/response flows.
130+
- **Immutability**: Avoid mutating shared state; clone objects before
131+
modification when needed.
132+
133+
## Quality gates
134+
135+
- Documented build/lint/type checks pass (where applicable).
136+
- Documented tests pass (where applicable).
137+
- Documentation updated to reflect changes when necessary.
138+
- Logs use appropriate levels (error, warn, info, debug).
139+
- Pull request title and commit messages follow
140+
[Conventional Commits](https://www.conventionalcommits.org/) format.
141+
142+
## Examples
143+
144+
### Naming coherence
145+
146+
**Good** (consistent style, clear semantics):
147+
148+
```typescript
149+
const thresholdValue = 0.06
150+
const processingMode = 'piecewise'
151+
type ChargingStationStatus = 'Available' | 'Preparing' | 'Charging'
152+
```
153+
154+
**Bad** (mixed styles, ambiguous):
155+
156+
```typescript
157+
const threshold_value = 0.06 // inconsistent case style
158+
const thresholdAim = 0.06 // synonym creates ambiguity
159+
type charging_station_status // wrong casing for type
160+
```
161+
162+
### Promise-based request/response pattern
163+
164+
**Good** (proper async flow):
165+
166+
```typescript
167+
protected handleProtocolRequest(
168+
uuid: string,
169+
procedureName: ProcedureName,
170+
payload: RequestPayload
171+
): Promise<ResponsePayload> {
172+
return new Promise<ResponsePayload>((resolve, reject) => {
173+
this.pendingRequests.set(uuid, { reject, resolve })
174+
this.sendBroadcastChannelRequest(uuid, procedureName, payload)
175+
})
176+
}
177+
```
178+
179+
**Bad** (returns void, no Promise):
180+
181+
```typescript
182+
protected handleProtocolRequest(
183+
uuid: string,
184+
procedureName: ProcedureName,
185+
payload: RequestPayload
186+
): void {
187+
this.sendBroadcastChannelRequest(uuid, procedureName, payload)
188+
// Response never reaches caller!
189+
}
190+
```
191+
192+
### Statistical reporting
193+
194+
```markdown
195+
| Metric | Value | Interpretation |
196+
| ----------- | ----- | --------------------- |
197+
| KL(A‖B) | 0.023 | < 0.1: low divergence |
198+
| Effect size | 0.12 | small to medium |
199+
```
200+
201+
---
202+
203+
By following these instructions, Copilot should propose changes that are
204+
consistent and maintainable across languages.

.github/workflows/internal-benchmark.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ jobs:
4343
--file benchmark-report.json \
4444
--err \
4545
--github-actions ${{ secrets.GITHUB_TOKEN }} \
46-
"deno task benchmark:tatami-ng"
46+
"deno task benchmark:tinybench"

.opencode/agent/review.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
description: Reviews code.
3+
mode: subagent
4+
temperature: 0.1
5+
tools:
6+
write: false
7+
edit: false
8+
bash: false
9+
---
10+
11+
You are in code review mode. Focus on:
12+
13+
- Code quality
14+
- Best practices
15+
- Algorithmic
16+
- Bugs
17+
- Edge cases
18+
- Performance
19+
- Security
20+
21+
Provide constructive and detailed feedbacks.

.opencode/command/format.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
description: Run code linter and formatter.
3+
---
4+
5+
Run code linter and formatter with autofixes.\
6+
Raw output:\
7+
!`deno task format && deno task lint:fix`\
8+
Summarize code linter or formatter failures and propose targeted fixes.

.opencode/command/test.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
description: Run test suite.
3+
---
4+
5+
Run test suite.\
6+
Raw output:\
7+
!`deno task test`\
8+
Summarize failing tests and propose targeted fixes.

.serena/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/cache
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Code Style and Conventions
2+
3+
## TypeScript/JavaScript Conventions
4+
5+
- **Imports**: Use `.ts` extensions for TypeScript imports, relative paths from
6+
`src/`
7+
- **Naming**:
8+
- camelCase for variables and functions
9+
- PascalCase for classes, types, enums, interfaces
10+
- **Types**: Explicit types over `any`, use type guards, avoid non-null
11+
assertions (`!`)
12+
- **Async**: Prefer async/await over raw Promises, handle rejections with
13+
try/catch
14+
- **Error Handling**: Use typed errors with structured properties
15+
16+
## Formatting (Deno fmt)
17+
18+
- 2-space indentation
19+
- Single quotes for strings
20+
- No semicolons
21+
- Trailing commas (ES5 style)
22+
23+
## JSDoc Comments
24+
25+
- All functions should have proper JSDoc comments
26+
- Include meaningful descriptions for the function purpose
27+
- Document all parameters with `@param {type} name - description`
28+
- Document return values with `@returns {type} description`
29+
- Empty comments like `/** */` should be filled with proper documentation
30+
31+
## Worker Patterns
32+
33+
- Use MessageChannel/MessagePort for worker communication
34+
- Use postMessage/onmessage for worker messaging
35+
- Store Promise resolvers in Maps for async operations
36+
37+
## Testing
38+
39+
- Use `@std/expect` and `@std/testing/bdd`
40+
- Test files should have `.mjs` extension
41+
- Test files should be in `tests/` directory
42+
43+
## Architecture Principles
44+
45+
- Follow DRY principle (Don't Repeat Yourself)
46+
- Maintain single source of truth for configuration
47+
- Use design patterns (factory/strategy) where appropriate
48+
- Optimize for minimal time/space complexity
49+
- English-only code and documentation
50+
- Tests-first mindset
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Codebase Structure
2+
3+
## Root Directory Structure
4+
5+
```
6+
/
7+
├── src/ # Main source code
8+
│ ├── pools/ # Pool implementations and strategies
9+
│ ├── queues/ # Queue implementations
10+
│ ├── worker/ # Worker abstractions and implementations
11+
│ └── mod.ts # Main module exports
12+
├── tests/ # Test files (.mjs extension)
13+
├── examples/ # Usage examples for different runtimes
14+
│ ├── deno/ # Deno-specific examples
15+
│ └── bun/ # Bun-specific examples
16+
├── benchmarks/ # Performance benchmarks
17+
├── docs/ # Documentation files
18+
├── dist/ # Built/bundled files
19+
├── .github/ # GitHub workflows and configs
20+
└── deno.json # Deno configuration
21+
22+
## Key Source Files
23+
- `src/mod.ts` - Main entry point with exports
24+
- `src/pools/abstract-pool.ts` - Base pool implementation
25+
- `src/pools/thread/fixed.ts` - Fixed thread pool
26+
- `src/pools/thread/dynamic.ts` - Dynamic thread pool
27+
- `src/worker/abstract-worker.ts` - Base worker class
28+
- `src/worker/thread-worker.ts` - Thread worker implementation
29+
30+
## Architecture Patterns
31+
- Factory pattern for pool creation
32+
- Strategy pattern for worker selection
33+
- Observer pattern for pool events
34+
- Template method pattern for abstract classes
35+
36+
## Module Organization
37+
- Each module has clear separation of concerns
38+
- Types are defined in separate files or alongside implementations
39+
- Utilities are separated from core logic
40+
- Test files mirror source structure in tests/ directory
41+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Poolifier Web Worker Project Overview
2+
3+
## Purpose
4+
5+
Poolifier Web Worker is a TypeScript/JavaScript library that provides worker
6+
pool implementations for Deno, Bun, and browser environments using the Web
7+
Worker API. It enables CPU and/or I/O intensive task execution without blocking
8+
the main event loop.
9+
10+
## Key Features
11+
12+
- Fixed and dynamic pool size management
13+
- Worker choice strategies for task distribution
14+
- Lockless task queueing and rescheduling
15+
- Support for sync/async task functions
16+
- Multiple task functions with priority queuing
17+
- Error handling and performance monitoring
18+
- Zero runtime dependencies
19+
20+
## Tech Stack
21+
22+
- **Runtime**: Deno, Bun, Browser
23+
- **Language**: TypeScript with ESM modules
24+
- **Testing**: Deno test framework with @std/expect
25+
- **Benchmarking**: Tinybench and built-in Deno bench
26+
- **Formatting**: Deno fmt (2-space, single quotes, no semicolons)
27+
- **Linting**: Deno lint
28+
29+
## Target Platforms
30+
31+
- Deno >= 1.40.x
32+
- Bun >= 1.x
33+
- Modern browsers with Web Worker support

0 commit comments

Comments
 (0)