Skip to content

performance optimisation#2238

Open
arteck wants to merge 5 commits into
ioBroker:masterfrom
arteck:master
Open

performance optimisation#2238
arteck wants to merge 5 commits into
ioBroker:masterfrom
arteck:master

Conversation

@arteck
Copy link
Copy Markdown
Contributor

@arteck arteck commented May 20, 2026

No description provided.

Copilot AI review requested due to automatic review settings May 20, 2026 05:14
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a set of runtime performance optimizations in the JavaScript adapter (primarily src/main.ts and src/lib/sandbox.ts) plus scheduler bugfixes, and adds several regression/performance-focused test suites to validate the changes.

Changes:

  • Replace several hot-path linear scans / repeated allocations with Set/Map lookups and precomputed structures (e.g., stateIdSet, subscriptionsObjectMap, sendTo instance cache, timersByScript).
  • Improve scheduler correctness and timer management (monthDiff fix, start boundary condition, timer leak mitigation, astro “yesterday” calculation, deterministic _getId).
  • Add new regression and micro-benchmark style tests covering scheduler fixes and performance improvements.

Reviewed changes

Copilot reviewed 20 out of 36 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
test/testSchedulerBugfixes.js New regression tests for scheduler bugfixes (monthDiff, timer lifecycle, boundary conditions, astro times, id uniqueness).
test/testMainPerformance.js New correctness + benchmark-style tests for data-structure optimizations (binary remove, Set vs Array).
test/performance.test.js New combined correctness/performance tests for multiple main.ts optimizations.
test/performance-improvements.test.js New baseline/expectation regression tests for planned main.ts performance improvements.
test/io-improvements.test.js New baseline/expectation regression tests for sandbox I/O hot-path optimizations.
src/types.d.ts Update public/internal typings to reflect new Set/Map based structures in runtime context and scripts.
src/main.ts Core performance changes: status text table hoist, state ID Set + binary ops, object subscription map, sendTo cache invalidation, unload safety, reverse name map, timers reverse index, etc.
src/lib/scheduler.ts Scheduler bugfixes + timer management improvements + deterministic ID generation.
src/lib/sandbox.ts Sandbox hot-path optimizations (Object.assign, Set-based dedupe, Set-backed adapterSubs/channels/devices/enums, sendTo cache, timers reverse index hooks, subscription dispatch map, Set-backed interval/timeout tracking).
src/lib/eventObj.ts Optimize enum dedup via Sets and adapt to context.enums being a Set.
src-editor/package.json Version bump (9.2.1 → 9.2.2).
src-editor/package-lock.json Lockfile version bump corresponding to editor package version.
src-admin/package.json Version bump (9.2.1 → 9.2.2).
src-admin/package-lock.json Lockfile version bump corresponding to admin package version.
build/types.d.ts Generated typings updated to match src/types.d.ts.
build/main.js Generated build output reflecting src/main.ts changes.
build/lib/scheduler.js Generated build output reflecting src/lib/scheduler.ts changes.
build/lib/sandbox.js Generated build output reflecting src/lib/sandbox.ts changes.
build/lib/eventObj.js.map Generated sourcemap updated for eventObj changes.
build/lib/eventObj.js Generated build output reflecting src/lib/eventObj.ts changes.
admin/tab.html Bundled admin entrypoint hash update.
admin/assets/ScriptEditor-Cryz6vV4.js Bundled admin asset hash/content update.
admin/assets/AiChatPanel-Caoxu5lo.js Bundled admin asset hash/content update.
Files not reviewed (7)
  • admin/remoteEntry.js: Language not supported
  • build/lib/eventObj.js: Language not supported
  • build/lib/sandbox.js: Language not supported
  • build/lib/scheduler.js: Language not supported
  • build/main.js: Language not supported
  • src-admin/package-lock.json: Language not supported
  • src-editor/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main.ts Outdated
Comment on lines 2190 to 2194
for (const id in res) {
if (Object.prototype.hasOwnProperty.call(res, id)) {
this.stateIds.push(id);
this.stateIdSet.add(id);
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after the loop we need sorted array

Comment thread src/main.ts Outdated
Comment on lines +853 to +854
// Precompute once – avoids string template alloc on every setState call
this._adapterFrom = `system.adapter.${this.namespace}`;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleted

Comment thread src/lib/sandbox.ts
Comment on lines 2792 to +2796
: isAck,
scriptName: name,
});
// Keep reverse-index in sync for O(1) cleanup in stopScript
if (!context.timersByScript.has(name)) {
Comment thread src/lib/sandbox.ts Outdated
Comment on lines +2829 to +2837
delete timers[id];
}
}
// IO-7: timersByScript Reverse-Index aktualisieren wenn State keine Timer mehr hat
if (!timers[id]) {
const scriptName = name; // name = Script-Name aus sandBox()-Closure
const stateIds = context.timersByScript.get(scriptName);
if (stateIds) {
stateIds.delete(id);
Comment thread src/lib/sandbox.ts
Comment on lines 2813 to 2819
if (timers[id]) {
for (let i = timers[id].length - 1; i >= 0; i--) {
if (timerId === undefined || timers[id][i].id === timerId) {
clearTimeout(timers[id][i].t);
if (timerId !== undefined) {
timers[id].splice(i, 1);
}
Comment thread test/performance.test.js
Comment on lines +60 to +66
it('Map-Instanz wird nur EINMAL erzeugt – kein GC-Druck durch neue Objekte', () => {
const start = process.memoryUsage().heapUsed;
for (let i = 0; i < 100_000; i++) httpStatusText(500);
const end = process.memoryUsage().heapUsed;
// Heap-Delta sollte minimal sein (< 1 MB)
assert.ok(end - start < 1024 * 1024, `Zu viel Heap-Zuwachs: ${end - start} Bytes`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants