mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
perf: bound DM subsystem network concurrency
Replaces unbounded Promise.all with pMap and RELAY_BACKGROUND_CONCURRENCY (3) in js/nostr/dmSignalEvents.js and js/services/dmNostrService.js to prevent network saturation. Includes context logs and daily performance report. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
de7fc9dbec
commit
799c336bf3
9 files changed
+1425
-10
No files matched your search
@@ -0,0 +1,20 @@
|
|||||||
|
# Context - Perf Agent - 2026-02-17
|
||||||
|
|
||||||
|
## Goal
|
||||||
|
Improve application responsiveness by bounding concurrency in background network tasks, specifically for DM signal events and DM service operations.
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
- `js/nostr/dmSignalEvents.js`: Fix unbounded `Promise.all` in `publishDmReadReceipt` and `publishDmTypingIndicator`.
|
||||||
|
- `js/services/dmNostrService.js`: Fix unbounded `Promise.all` in `connect` and `publishSignedEvent`.
|
||||||
|
- `content/docs/guides/upload-content.md`: Fix documentation port number (5500 -> 3000).
|
||||||
|
|
||||||
|
## Assumptions
|
||||||
|
- `pMap` utility works as expected.
|
||||||
|
- `RELAY_BACKGROUND_CONCURRENCY` (3) is an appropriate limit for these operations.
|
||||||
|
|
||||||
|
## Definition of Done
|
||||||
|
- All `Promise.all` usages in targeted functions are replaced with `pMap` with concurrency limits.
|
||||||
|
- `npm run lint` passes.
|
||||||
|
- `npm run test:dm:unit` passes.
|
||||||
|
- `npm run test:dm:integration` passes.
|
||||||
|
- `content/docs/guides/upload-content.md` is updated.
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
# Daily Performance Report - 2026-02-17
|
||||||
|
|
||||||
|
**Summary:** Bounded concurrency for DM signal events and DM service initialization to prevent network saturation.
|
||||||
|
|
||||||
|
## Findings & Fixes
|
||||||
|
|
||||||
|
### P0: Unbounded Concurrency in DM Subsystem
|
||||||
|
- **Files:** `js/nostr/dmSignalEvents.js`, `js/services/dmNostrService.js`
|
||||||
|
- **Impact:** `Promise.all` was used to map over all relays (potential for 20+ connections simultaneously) for DM read receipts, typing indicators, and service connections.
|
||||||
|
- **Fix:** Replaced with `pMap` using `RELAY_BACKGROUND_CONCURRENCY` (3).
|
||||||
|
- **Verification:** `npm run test:dm:unit` and `npm run test:dm:integration` passed.
|
||||||
|
|
||||||
|
### Docs Audit
|
||||||
|
- **Port Alignment:** Verified `content/docs/guides/upload-content.md` correctly specifies port 3000 for CORS, aligning with previous remediation. No changes needed.
|
||||||
|
|
||||||
|
## Metrics
|
||||||
|
- **Login Time:** N/A (change affects background network tasks).
|
||||||
|
- **DM Decrypt Queue:** N/A (network bounding).
|
||||||
|
|
||||||
|
## Decisions
|
||||||
|
- Used `RELAY_BACKGROUND_CONCURRENCY` (3) for DM operations to match relay manager behavior.
|
||||||
|
|
||||||
|
## PRs / Commits
|
||||||
|
- `perf: bound DM subsystem network concurrency` (this change).
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
# Decisions - Perf Agent - 2026-02-17
|
||||||
|
|
||||||
|
- **Decision:** Use `pMap` with `RELAY_BACKGROUND_CONCURRENCY` (3) for DM signal publishing and DM service connection/publishing.
|
||||||
|
- **Rationale:** Prevents network saturation when users have many relays configured. `Promise.all` launches all requests simultaneously, which can cause timeouts or UI lag.
|
||||||
|
- **Decision:** Update documentation port to 3000.
|
||||||
|
- **Rationale:** Matches standard dev environment default.
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# perf-agent Daily Run - 2026-02-17
|
||||||
|
|
||||||
|
## Status: Completed
|
||||||
|
|
||||||
|
**Goals:**
|
||||||
|
- Identify and fix unbounded concurrency in network operations.
|
||||||
|
- Audit upload documentation.
|
||||||
|
|
||||||
|
**Actions:**
|
||||||
|
- **Identified:** Unbounded `Promise.all` usage in `js/nostr/dmSignalEvents.js` and `js/services/dmNostrService.js`.
|
||||||
|
- **Fixed:** Replaced with `pMap` and `RELAY_BACKGROUND_CONCURRENCY` (3).
|
||||||
|
- **Verified:** Documentation in `content/docs/guides/upload-content.md` correctly specifies port 3000.
|
||||||
|
- **Tested:** Unit and integration tests for DM subsystem passed.
|
||||||
|
|
||||||
|
**Files Changed:**
|
||||||
|
- `js/nostr/dmSignalEvents.js`
|
||||||
|
- `js/services/dmNostrService.js`
|
||||||
|
- `daily-perf-report-2026-02-17.md`
|
||||||
|
- Context/Logs: `context/`, `todo/`, `decisions/`, `test_logs/`
|
||||||
|
|
||||||
|
**Metrics:**
|
||||||
|
- DM network concurrency bounded to 3 (was unbounded).
|
||||||
@@ -10,6 +10,8 @@ import { queueSignEvent } from "./signRequestQueue.js";
|
|||||||
import { getActiveSigner } from "../nostrClientRegistry.js";
|
import { getActiveSigner } from "../nostrClientRegistry.js";
|
||||||
import { isSessionActor } from "./sessionActor.js";
|
import { isSessionActor } from "./sessionActor.js";
|
||||||
import { sanitizeRelayList as sanitizeRelayUrls } from "./nip46Client.js";
|
import { sanitizeRelayList as sanitizeRelayUrls } from "./nip46Client.js";
|
||||||
|
import { pMap } from "../utils/asyncUtils.js";
|
||||||
|
import { RELAY_BACKGROUND_CONCURRENCY } from "./relayConstants.js";
|
||||||
|
|
||||||
const DEFAULT_TYPING_EXPIRY_SECONDS = 15;
|
const DEFAULT_TYPING_EXPIRY_SECONDS = 15;
|
||||||
|
|
||||||
@@ -139,8 +141,10 @@ export async function publishDmReadReceipt(
|
|||||||
client.writeRelays || client.relays,
|
client.writeRelays || client.relays,
|
||||||
);
|
);
|
||||||
|
|
||||||
const publishResults = await Promise.all(
|
const publishResults = await pMap(
|
||||||
relayList.map((url) => publishEventToRelay(client.pool, url, signedEvent)),
|
relayList,
|
||||||
|
(url) => publishEventToRelay(client.pool, url, signedEvent),
|
||||||
|
{ concurrency: RELAY_BACKGROUND_CONCURRENCY },
|
||||||
);
|
);
|
||||||
|
|
||||||
const acceptedRelays = publishResults
|
const acceptedRelays = publishResults
|
||||||
@@ -280,8 +284,10 @@ export async function publishDmTypingIndicator(
|
|||||||
client.writeRelays || client.relays,
|
client.writeRelays || client.relays,
|
||||||
);
|
);
|
||||||
|
|
||||||
const publishResults = await Promise.all(
|
const publishResults = await pMap(
|
||||||
relayList.map((url) => publishEventToRelay(client.pool, url, signedEvent)),
|
relayList,
|
||||||
|
(url) => publishEventToRelay(client.pool, url, signedEvent),
|
||||||
|
{ concurrency: RELAY_BACKGROUND_CONCURRENCY },
|
||||||
);
|
);
|
||||||
|
|
||||||
const acceptedRelays = publishResults
|
const acceptedRelays = publishResults
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import { sanitizeRelayList } from "../nostr/nip46Client.js";
|
|||||||
import { publishEventToRelay } from "../nostrPublish.js";
|
import { publishEventToRelay } from "../nostrPublish.js";
|
||||||
import logger from "../utils/logger.js";
|
import logger from "../utils/logger.js";
|
||||||
import { SHORT_TIMEOUT_MS } from "../constants.js";
|
import { SHORT_TIMEOUT_MS } from "../constants.js";
|
||||||
|
import { pMap } from "../utils/asyncUtils.js";
|
||||||
|
import { RELAY_BACKGROUND_CONCURRENCY } from "../nostr/relayConstants.js";
|
||||||
|
|
||||||
const DEFAULT_BACKOFF = {
|
const DEFAULT_BACKOFF = {
|
||||||
baseMs: 1000,
|
baseMs: 1000,
|
||||||
@@ -272,10 +274,12 @@ class DmNostrService {
|
|||||||
|
|
||||||
await this.ensurePool();
|
await this.ensurePool();
|
||||||
|
|
||||||
await Promise.all(
|
await pMap(
|
||||||
this.relays.map(async (relayUrl) => {
|
this.relays,
|
||||||
|
async (relayUrl) => {
|
||||||
await this.connectRelay(relayUrl);
|
await this.connectRelay(relayUrl);
|
||||||
}),
|
},
|
||||||
|
{ concurrency: RELAY_BACKGROUND_CONCURRENCY },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -654,8 +658,9 @@ class DmNostrService {
|
|||||||
|
|
||||||
await this.ensurePool();
|
await this.ensurePool();
|
||||||
|
|
||||||
const results = await Promise.all(
|
const results = await pMap(
|
||||||
relayList.map(async (relayUrl) => {
|
relayList,
|
||||||
|
async (relayUrl) => {
|
||||||
let result;
|
let result;
|
||||||
try {
|
try {
|
||||||
result = await publishEventToRelay(this.pool, relayUrl, signedEvent);
|
result = await publishEventToRelay(this.pool, relayUrl, signedEvent);
|
||||||
@@ -674,7 +679,8 @@ class DmNostrService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return { ...result, relayUrl };
|
return { ...result, relayUrl };
|
||||||
}),
|
},
|
||||||
|
{ concurrency: RELAY_BACKGROUND_CONCURRENCY },
|
||||||
);
|
);
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,16 @@
|
|||||||
|
# Test Log - Perf Agent - 2026-02-17
|
||||||
|
|
||||||
|
## Pre-fix
|
||||||
|
- [x] Lint check: Passed (with expected vendor warnings).
|
||||||
|
- [x] DM Unit Tests: Passed.
|
||||||
|
- [x] DM Integration Tests: Passed.
|
||||||
|
|
||||||
|
## Post-fix
|
||||||
|
- [x] Lint check: Passed.
|
||||||
|
- [x] DM Unit Tests: Passed.
|
||||||
|
- [x] DM Integration Tests: Passed.
|
||||||
|
|
||||||
|
## Details
|
||||||
|
- `npm run lint` showed `vendor/webtorrent.min.js` file size warning, which is expected/unrelated.
|
||||||
|
- `npm run test:dm:unit` passed 100%.
|
||||||
|
- `npm run test:dm:integration` passed 100%.
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# TODO - Perf Agent - 2026-02-17
|
||||||
|
|
||||||
|
- [ ] Fix `js/nostr/dmSignalEvents.js` @high
|
||||||
|
- [ ] Fix `js/services/dmNostrService.js` @high
|
||||||
|
- [ ] Update `content/docs/guides/upload-content.md` @low
|
||||||
|
- [ ] Run `npm run lint`
|
||||||
|
- [ ] Run `npm run test:dm:unit`
|
||||||
|
- [ ] Run `npm run test:dm:integration`
|
||||||
Reference in new issue
Block a user