Skip to content

[Performance] Optimize PhraseMakerGrid.syncMarkedBlocks matching and deduplication #6124

@Rohit-rk07

Description

@Rohit-rk07

Problem

syncMarkedBlocks() currently performs:

  • nested matching using JSON.stringify(...) between _blockMap and _blockMapHelper
  • deduplication using filter(...findIndex(...))

For larger phrase matrices, this increases CPU usage and creates unnecessary temporary strings.

Why It Matters

This method runs during matrix synchronization in PhraseMaker. The current approach scales poorly as matrix size grows.

Proposed Change

  • Build a keyed lookup map for _blockMapHelper rhythm refs once per call.
  • Replace nested stringify matching with O(1) key lookup.
  • Replace quadratic dedupe with a single-pass Set-based dedupe (preserve first occurrence order).

Scope

  • File: js/widgets/PhraseMakerGrid.js
  • Method: syncMarkedBlocks(pm)

Acceptance Criteria

  • Functional behavior remains unchanged.
  • Ordering remains stable (first occurrence kept).
  • Method avoids nested stringify equality loops and findIndex-based dedupe.
  • Existing PhraseMakerGrid unit tests pass.

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