Skip to content

structuredClone regression causes high CPU/heat in v1.2.9+ #14458

Closed

Description

@monotykamary

Description

Commits 8ad60b1 and 01d5187 replaced remeda.clone() with native structuredClone(), causing significant performance degradation. This results in sustained high CPU usage (40%+) and laptop overheating even during idle periods.

Benchmark results show structuredClone is 20-33x slower for large session data and 1.8x slower overall:

  • Small data: 1.3x faster (acceptable)
  • Large data: 0.05x slower (20x slowdown - critical)
  • Realistic workload: 246ms vs 134ms (1.8x slower)

The performance regression affects all background operations that process session data, including history management, message streaming, and scheduled cleanup tasks.

OpenCode version

v1.2.9, v1.2.10

Steps to reproduce

  1. Upgrade to v1.2.9 or v1.2.10
  2. Use opencode normally with typical session sizes (>50 messages)
  3. Observe Activity Monitor showing sustained 40%+ CPU during idle
  4. Laptop heats up significantly even when not actively using opencode

Operating System

macOS (observed), likely affects all platforms

Terminal

N/A - affects both TUI and background server processes

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    perfIndicates a performance issue or need for optimization
    needs:complianceThis means the issue will auto-close after 2 hours.
    and removed
    needs:complianceThis means the issue will auto-close after 2 hours.
    on Feb 20, 2026
  2. github-actions commented on Feb 20, 2026

    @github-actions
    Contributor

    Thanks for updating the issue! It now follows the contributing guidelines with the required template structure, description, reproduction steps, and system context. Removing the compliance flag.

  3. monotykamary commented on Feb 20, 2026

    @monotykamary
    ContributorAuthor

    Benchmark code used to verify the performance regression:

    #!/usr/bin/env bun
    /**
     * Benchmark comparing structuredClone vs previous implementation
     * Tests actual use cases from opencode codebase
     */
    
    import { clone } from "remeda"
    
    // Generate realistic mock data similar to opencode's message structures
    const generateMessage = (id: number, size: "small" | "medium" | "large") => {
      const textContent = {
        small: "Hello, this is a short message.",
        medium: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. ".repeat(50),
        large: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. ".repeat(500),
      }[size]
    
      return {
        id,
        info: {
          id,
          role: id % 2 === 0 ? "user" : "assistant",
          time: Date.now(),
          name: null,
        },
        parts: [
          {
            type: "text",
            text: textContent,
            ignored: false,
            synthetic: false,
          },
        ],
      }
    }
    
    // Benchmark runner
    const benchmark = async <T>(
      name: string,
      fn: () => T,
      iterations: number,
    ): Promise<{ avgMs: number }> => {
      const start = performance.now()
      for (let i = 0; i < iterations; i++) fn()
      return { avgMs: (performance.now() - start) / iterations }
    }
    
    const runBenchmarks = async () => {
      const results = []
    
      for (const size of ["small", "medium", "large"] as const) {
        const messages = Array.from({ length: 20 }, (_, i) => generateMessage(i, size))
    
        const oldImpl = await benchmark("old impl", () => clone(messages), 10000)
        const newImpl = await benchmark("structuredClone", () => structuredClone(messages), 10000)
    
        results.push({ size, oldImpl: oldImpl.avgMs, newImpl: newImpl.avgMs })
      }
    
      console.table(results)
    }
    
    runBenchmarks()

    Run with:

    • bun run benchmark/clone.ts
    • bun run --expose-gc benchmark/clone.ts (for memory stats)

    The benchmark simulates opencode's actual data structures (session messages, prompt history) with realistic sizes. Results show structuredClone becomes exponentially slower as data size increases.

  4. monotykamary commented on Feb 20, 2026

    @monotykamary
    ContributorAuthor

    May or may not be a red herring (could also be all of the FS stuff we're doing to make stuff platform agnostic). This one was the most obvious one I found this week.

  5. rekram1-node commented on Feb 20, 2026

    @rekram1-node
    Contributor

    Are u sure??

    The clone call is incredibly expensive. I suspect due to the reference saving mechanism and linear lookup:
    
    https://github.com/remeda/remeda/blob/047c93e314bb9351b3ab93b34ce4b6cf67df7b1d/packages/remeda/src/clone.ts#L80
    
    Replacing it with const sessionMessages = structuredClone(msgs) call directly is much faster. Still takes 1352ms in this case, suggesting a large msgs object.
    
  6. rekram1-node commented on Feb 20, 2026

    @rekram1-node
    Contributor

    are u using any plugins?

  7. monotykamary commented on Feb 20, 2026

    @monotykamary
    ContributorAuthor

    my opencode is virgin

  8. monotykamary commented on Feb 20, 2026

    @monotykamary
    ContributorAuthor

    My colleague does experience higher CPU. I see it with really long conversation threads + a ton of subagents; but otherwise, it's pretty okay at the moment. Might need to look in deeper.

  9. github-actions commented on Apr 22, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)perfIndicates a performance issue or need for optimization

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions