Skip to content

perf(mongodb): zero-allocation JSON path builder and eliminate per-node RegExp compilation #1525

Closed

Description

@ZhuchkaTriplesix

Problem

In MongoDocumentTreeView (lib/features/mongodb/mongo_document_tree_view.dart), appendJsonPath(parentPath, keyOrIndex) instantiates RegExp(r'^[a-zA-Z_$][a-zA-Z0-9_$]*$') inside the function on every single node of a document tree.
For 1,000 documents with 20 fields each, this results in 20,000 regex compilations and matcher allocations on every render.

Solution

  • Replace runtime RegExp construction with a zero-allocation character validation helper using codeUnitAt.
  • Cache or precompile static pattern if regex is retained.

Benefits

  • 0 RegExp allocations during MongoDB tree traversal.
  • ~15-20x faster path construction for nested documents.

Activity

  1. added
    performanceTheme parser epic label: performance
    enhancementNew feature or request
    backendBackend database driver execution and queries
    connectionsDatabase connections, URI parsing, pools
    on Oct 12, 2026
  2. added this to the 0.5.0 milestone on Oct 12, 2026
  3. added a commit that references this issue on Oct 15, 2026
  4. ZhuchkaTriplesix commented on Oct 25, 2026

    @ZhuchkaTriplesix
    MemberAuthor

    Fixed on dev by 8517500: perf(mongodb): check JSON path identifiers from code units. It reaches main with the next dev to main merge (closed after checking the code and its tests).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium priority / Parity & RefactoringbackendBackend database driver execution and queriesconnectionsDatabase connections, URI parsing, poolsenhancementNew feature or requestperformanceTheme parser epic label: performance

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions