Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Aggregate per-item logging inside fan-out loops instead of logging each iteration
A log call inside a broadcast or fan-out loop costs an argument object per item even when the level is disabled, and when it is enabled it multiplies log volume by the number of recipients.
Bad example
| 1 | for (const client of clients) { |
| 2 | if (!client.topics.has(topic)) { |
| 3 | emitDebug("skipping client", { id: client.id, topic }); // per client, per message |
| 4 | continue; |
| 5 | } |
| 6 | client.write(payload); |
| 7 | } |
Explanation (EN)
Per-recipient logs multiply allocation work and log volume for one logical operation.
Objašnjenje (HR)
Logiranje za svakog primatelja umnožava alokacije i količinu logova za jednu logičku operaciju.
Good example
| 1 | let skipped = 0; |
| 2 | for (const client of clients) { |
| 3 | if (!client.topics.has(topic)) { |
| 4 | skipped += 1; |
| 5 | continue; |
| 6 | } |
| 7 | client.write(payload); |
| 8 | } |
| 9 | emitInfo("broadcast", { topic, delivered: clients.length - skipped, skipped }); |
Explanation (EN)
One line per broadcast carries the same information as a counter, with no per-item allocation and no volume that scales with recipients.
Objašnjenje (HR)
Jedna linija po emitiranju nosi istu informaciju kao brojac, bez alokacije po stavci i bez volumena koji raste s brojem primatelja.
Notes (EN)
Inside a high-volume fan-out loop, assess log cardinality and argument-construction cost; aggregate outcomes at the operation boundary where per-recipient details are unnecessary.
Bilješke (HR)
U petlji s mnogo paralelnih operacija procijeni količinu logova i trošak izrade njihovih argumenata. Kada pojedinosti po primatelju nisu potrebne, objedini ishode na razini cijele operacije.
Exceptions / Tradeoffs (EN)
Retain necessary audit/security events and gated per-item diagnostics; lazy logger arguments may already avoid construction costs.