Skip to content

Expensive calls tocider-current-repl in latency sensitive contexts #3344

@yuhan0

Description

@yuhan0

Expected behavior

Several features in Cider run on short idle timers or hooks that run synchronously while the user is typing/editing.

  • Eldoc hints
  • Company etc. auto completion
  • electric / aggressive indentation modes
  • Auto formatting

Any latency or momentary freezes in these contexts make for a unpleasant editing experience, so they should be made as optimized as possible.

Actual behavior

Many of these features call the harmless-looking (cider-current-repl) under the hood, and profiling shows it is in fact an expensive operation involving various heuristics and filesystem lookups.

The performance impact grows ~linearly with the number of open REPL connections, See #3343 for more details and a sample backtrace.

  • cider-eldoc and cider-complete via. (cider-connected-p)
  • clojure-indent-line via cider--get-symbol-indent -> cider-resolve-var.

These are the main ones that showed up when profiling my own editing usage - eg. I don't use cider-format but that seems like it should be affected too. Searching the codebase also finds various cider-nrepl-sync-request functions taking an optional connection arg which forwards to a call to (cider-current-repl).

Steps to reproduce the problem

Set the eldoc timer to a short delay to magnify the issues:
(setq eldoc-idle-delay 0.01)
then jack-in to many projects simultaneously.

Navigating or typing in a connected clj source buffer should get increasingly laggy with the number of open connections.

Environment & Version information

CIDER version information

;; CIDER 1.7.0 (Côte d'Azur), nREPL 1.0.0
;; Clojure 1.11.1, Java 20

Lein / Clojure CLI version

Clojure CLI version 1.11.1.1273

Emacs version

GNU Emacs 29.0.90

Operating system

macOS 12.5.1

JDK distribution

Temurin jdk-20.0.1+9

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions