Skip to content

Eliminate startup delay when slow-starting LLM completion provider is configured#14910

Merged
krassowski merged 3 commits intoipython:mainfrom
krassowski:fix-lag-due-to-llm
May 31, 2025
Merged

Eliminate startup delay when slow-starting LLM completion provider is configured#14910
krassowski merged 3 commits intoipython:mainfrom
krassowski:fix-lag-due-to-llm

Conversation

@krassowski
Copy link
Copy Markdown
Member

@krassowski krassowski commented May 30, 2025

  • Add a failing test
  • Delay LLM loading to the first invocation
  • Update recommended import paths

Results with ExampleCompletionProvider:

Before After
2.189 s ± 0.019 s 623.9 ms ± 14.7 ms
Details

Before

Benchmark 1: ipython --TerminalInteractiveShell.llm_provider_class=examples.auto_suggest_llm.ExampleCompletionProvider -c exit
  Time (mean ± σ):      2.189 s ±  0.019 s    [User: 3.848 s, System: 0.286 s]
  Range (min … max):    2.171 s …  2.226 s    10 runs

After

Benchmark 1: ipython --TerminalInteractiveShell.llm_provider_class=examples.auto_suggest_llm.ExampleCompletionProvider -c exit
  Time (mean ± σ):     623.9 ms ±  14.7 ms    [User: 480.7 ms, System: 130.6 ms]
  Range (min … max):   600.0 ms … 650.6 ms    10 runs

@krassowski krassowski force-pushed the fix-lag-due-to-llm branch from 3b57695 to c0a0d7c Compare May 30, 2025 15:25
@krassowski krassowski marked this pull request as ready for review May 30, 2025 15:30
@krassowski krassowski requested a review from Copilot May 30, 2025 23:12
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR reduces startup delays when configuring a slow-starting LLM completion provider by delaying its instantiation until the first request, and updates import paths to the new jupyter_ai_magics package.

  • Add a test (test_slow_llm_provider_should_not_block_init) to verify that setting the provider class doesn’t block startup.
  • Introduce lazy initialization via an _init_llm_provider constructor reference, replacing eager instantiation.
  • Update import paths in tests, examples, and core code to reference jupyter_ai_magics.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_shortcuts.py Added performance test for non-blocking provider configuration
tests/fake_llm.py Added SlowStartingCompletionProvider and updated BaseProvider import
examples/auto_suggest_llm.py Updated import paths to jupyter_ai_magics
IPython/terminal/shortcuts/auto_suggest.py Replaced eager _llm_provider with lazy _init_llm_provider and instance property
IPython/terminal/interactiveshell.py Deferred provider construction by assigning an init function
Comments suppressed due to low confidence (4)

IPython/terminal/shortcuts/auto_suggest.py:359

  • This import still references the old jupyter_ai path. Update it to the new jupyter_ai_magics.models.completion module for consistency.
            import jupyter_ai.completions.models as jai_models

IPython/terminal/interactiveshell.py:518

  • Typo in comment: 'Provisinal' should be 'Provisional'.
# Provisinal in 8.32

IPython/terminal/shortcuts/auto_suggest.py:176

  • The Callable type is used in the class annotation but not imported; add from typing import Callable to avoid a NameError.
_init_llm_provider: Callable | None

IPython/terminal/interactiveshell.py:511

  • The indentation of the def init_llm_provider() block is inconsistent and may cause an IndentationError. Align indentation levels to match the surrounding code.
                def init_llm_provider():

@krassowski krassowski added this to the 8.37 milestone May 31, 2025
@krassowski krassowski changed the title Reduce startup delay when slow-starting LLM completion provider is configured Eliminate startup delay when slow-starting LLM completion provider is configured May 31, 2025
@krassowski krassowski merged commit b7b2778 into ipython:main May 31, 2025
18 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/ipython that referenced this pull request May 31, 2025
krassowski added a commit that referenced this pull request May 31, 2025
…tarting LLM completion provider is configured) (#14912)

Backport PR #14910: Eliminate startup delay when slow-starting LLM
completion provider is configured
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants