Skip to content

Performance: ~10 object reads and ~4 state writes per incoming Zigbee message #3037

Closed

Description

@Schimi1983

I measured how many object/state calls the adapter makes per incoming Zigbee message, to find out where a lean improvement is possible without new caches or extra memory.

Setup
GitHub master (3.6.0-dev, incl. fix/numeric-presets), ZStack over LAN, 42 devices (mostly lights and plugs), 8 groups. The adapter methods (getObjectAsync, setState, …) were wrapped with counters, and every event/msg from the zigbee controller was counted. Measuring branch only, not meant for a PR: https://github.com/Schimi1983/ioBroker.zigbee/tree/measure/m0-4

Result (35 min, 232 messages)

Phase getObjectAsync setState other
normal operation (min 5–35, 178 messages) 9.9 per message 4.15 per message getState / getForeignObject / extendObject ≈ 0
adapter start (first ~5 min) ≈ 4,400 in total (≈ 100 per device) – 90× extendObjectAsync, 86× getForeignObjectAsync

Availability pings are included, so the per-message values are slightly too high.

Where the reads come from (lib/statescontroller.js)

  • onZigbeeEvent() → checkIfModelUpdate(): 1× getObjectAsync(device)
  • updateState() is called for every value of a message (typically value(s) + linkquality + available + msg_from_zigbee) and reads two objects each time: getObjectAsync(devId) and getObjectAsync(stateId)
  • → 1 + 2 × ~4 ≈ 9–10 reads per message, which matches the measurement
  • the device object in updateState() is only used for if (devObj); if the state object exists, the device exists as well
  • msg_from_zigbee is written for every message, also when nobody uses it

Proposal (small steps, no new data structures, no behaviour change by default)

  1. updateState(): read the device object only if the state object does not exist → saves ~4 reads per message (≈ 40 %).
  2. msg_from_zigbee: optional setting "write raw message to msg_from_zigbee" – default on (= current behaviour), so nothing changes for existing users; switching it off saves 1 write + 2 reads per message.
  3. Start: check whether the ≈ 100 object reads per device during start can be reduced (e.g. read the device object once per device in syncDevStates) – I'd look into this only after 1 and 2.

I would prepare 1 as a small PR first and measure again with the same branch. Would that be OK for you, or do you prefer a different approach?

Activity

  1. Schimi1983 commented on Nov 15, 2026

    @Schimi1983
    ContributorAuthor

    Follow-up with step 1 applied (branch perf/update-state-reads: updateState() reads the device object only when the state object is missing), measured the same way on the same installation:

    before with step 1 change
    getObjectAsync per message (normal operation, min 5–35) 9.9 5.7 −42 %
    setState per message 4.15 4.10 –
    getObjectAsync during adapter start (first 5 min) ≈ 4,870 ≈ 1,710 −65 %

    189 messages in the compared window (before: 178). No errors or warnings in the log, all devices reachable.

    The fix itself is a one-line move plus a comment: master...Schimi1983:ioBroker.zigbee:perf/update-state-reads

    If that's fine for you, I'll open it as a PR once one of my two open PRs is through.

  2. added a commit that references this issue on Nov 16, 2026
  3. Schimi1983 commented on Nov 18, 2026

    @Schimi1983
    ContributorAuthor

    Short wrap-up:

    So I consider this done and close the issue. Thanks!

  4. Schimi1983 commented on Nov 20, 2026

    @Schimi1983
    ContributorAuthor

    Short wrap-up:

    So I consider this done and close the issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions