Skip to content

Performance Issue: excessive structuredClone in runSubscribersWithMutationΒ #883

@daohoangson

Description

@daohoangson

The runSubscribersWithMutation function has a critical performance bottleneck causing long execution time with the potential to hang the browser completely.

Impact

  • The example dojo app has 26 active subscribers during streaming
  • Message arrays grow from 0 to 42 messages during a 742KB test run with ~200 events
  • Current execution time: 810ms
Traffic Events Trace
Image Image Image

Root Cause

This is in the hot path, called 2Γ— per streaming event (once for onEvent, once for specific event handler), but it:

  • Clones per subscriber even if they do not mutate
  • Does expensive change detection via JSON.stringify()

Proposed Solution

I have a working fix on my fork with two commits:

Expected Results

Image
  • New execution time: ~53ms (15x faster)
  • Eliminate serialization bottleneck visible in flame graphs

I'm ready to submit a PR once this approach is validated.

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