Skip to content

refactor: Extract common Data1D processing logic from sync modifiers #185

@andeplane

Description

@andeplane

Problem

The three sync modifiers (synccomputesmodifier.ts, syncfixesmodifier.ts, syncvariablesmodifier.ts) have ~80% code duplication, specifically in the Data1D processing logic (lines ~55-118 in each file).

Current Behavior

Each modifier contains nearly identical code for:

  • Getting data1DNames and checking size
  • Processing clearPerSync logic
  • Looping through data1DVector and extracting x/y values
  • Proper cleanup of WASM objects (data1DNamesWrapper, lmpData, data1DVector)

Expected Behavior

Extract the common Data1D processing logic into a shared helper function that can be reused by all three modifiers.

Proposed Solution

Create a shared helper function in src/modifiers/modifier.ts (or a new utility file):

function processData1D(
  modifier: LMPModifier,
  data1D: Data1D | undefined,
  input: ModifierInput,
  everything: boolean,
  syncDataPoints: boolean
): Data1D | undefined

This function should handle:

  1. Getting data1DNames wrapper and extracting size
  2. Checking if data1D needs to be created
  3. Processing clearPerSync logic
  4. Looping through data1DVector and extracting x/y values from WASM memory
  5. Proper cleanup of all WASM objects
  6. Returning the processed data1D object

Files to Modify

  • src/modifiers/modifier.ts (add helper function)
  • OR create new utility file if preferred

Benefits

  • Reduces code duplication (~125 lines per file → ~50-60 lines)
  • Makes maintenance easier (fix bugs/improvements in one place)
  • Ensures consistent WASM memory cleanup
  • Easier to add new modifiers in the future

Related

This is a prerequisite for issue #183 (memory leak fixes) and will make future improvements easier. Should be done after basic memory leak fixes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions