Skip to content

perf(move-file): batch tree write/delete operations #162

@LayZeeDK

Description

@LayZeeDK

Summary

Stage file writes/deletes during the move-file generator and apply them in batches to reduce virtual tree overhead.

Proposed Solution

interface FileOperation {
  type: 'write' | 'delete';
  path: string;
  content?: string;
}

const pendingFileOperations: FileOperation[] = [];

function scheduleFileWrite(path: string, content: string): void {
  pendingFileOperations.push({ type: 'write', path, content });
}

function scheduleFileDelete(path: string): void {
  pendingFileOperations.push({ type: 'delete', path });
}

function applyFileOperations(tree: Tree): void {
  const writes = pendingFileOperations.filter(op => op.type === 'write');
  const deletes = pendingFileOperations.filter(op => op.type === 'delete');

  for (const op of writes) {
    tree.write(op.path, op.content!);
  }

  for (const op of deletes) {
    tree.delete(op.path);
  }

  pendingFileOperations.length = 0;
}
  • Queue file operations and apply writes before deletes.
  • Integrate with format/flush lifecycle.

Tasks

  • Introduce a queue for pending file operations with types (write/delete)
  • Apply queued operations in an optimised order (writes first, then deletes)
  • Ensure ordering preserves existing behaviour and integration with formatting steps

Definition of Done

  • Existing benchmark and stress test suites are run before and after the change; include the performance deltas in the PR description. This is mandatory.
  • Unit/e2e tests keep passing.
  • Add documentation/comments explaining the batching approach if necessary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: futureFuture consideration performance optimization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions