Skip to content

Performance: inefficient O(N^2) ripgrep callback #37869

Closed

Description

@quark-zju

Description

Inefficient code:

Effect.sync(() => {
state.files.push(entry.path)
const parts = entry.path.split("/")
parts.slice(0, -1).forEach((_, index) => directories.add(parts.slice(0, index + 1).join("/") + path.sep))
state.directories = Array.from(directories)
}),

Array.from(directories) called per file. So O(files * dirs).

The path split-then-join also seems optimizable to avoid joins.

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Activity

  1. AceRothstein71 commented on Sep 17, 2026

    @AceRothstein71

    The per-entry Array.from(directories) plus repeated prefix joins made the initial filesystem scan O(files × directories). Directories now accumulate in place in a set and materialize once per query. The fix and coverage are on the branch of PR #48638.

  2. AceRothstein71 commented on Sep 17, 2026

    @AceRothstein71

    Fixed on the branch of PR #48638: state.directories is now a Set that accumulates prefixes in place (no per-entry Array.from, no per-prefix re-joins) and is materialized once per query.

  3. neriousy commented on Oct 19, 2026

    @neriousy
    Member

    The quadratic directory materialization is fixed in v2: the scan accumulates files and directories in Maps, and only materializes candidates when a search runs. Path-prefix split/join operations remain, but the per-file Array.from(directories) is gone.

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

Metadata

Metadata

Assignees

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