Skip to content

perf: defer Databricks Connect initialization to background thread#31

Merged
Hazzng merged 7 commits into
mainfrom
claude/databricks-startup-performance-AjokB
Apr 14, 2026
Merged

perf: defer Databricks Connect initialization to background thread#31
Hazzng merged 7 commits into
mainfrom
claude/databricks-startup-performance-AjokB

Conversation

@Hazzng

@Hazzng Hazzng commented Apr 14, 2026

Copy link
Copy Markdown
Owner

Kernel startup was blocking ~15s on DatabricksSession.getOrCreate()
before sending the "ready" signal. Now the kernel reports ready in
~1-2s by deferring spark initialization to a background thread.

A LazySparkSession proxy is placed in the namespace immediately so
'spark' in dir() is True. On first attribute access (e.g. spark.sql()),
the proxy blocks until the real session is available - but by then the
background init has had a head start (often already complete).

Key changes:

  • kernel_runner.py: Add LazySparkSession proxy, _SparkInitState,
    background thread init, thread-safe _write_json for stdout
  • persistentExecutor.ts: Handle new 'spark_ready' message type
  • utils.ts: Add showSparkReadyNotification, skip INITIALIZING status

https://claude.ai/code/session_01NCzUTPmDaWc5Rwr8xB4Zfu

Hazzng added 5 commits April 14, 2026 10:46
Kernel startup was blocking ~15s on DatabricksSession.getOrCreate()
before sending the "ready" signal. Now the kernel reports ready in
~1-2s by deferring spark initialization to a background thread.

A LazySparkSession proxy is placed in the namespace immediately so
'spark' in dir() is True. On first attribute access (e.g. spark.sql()),
the proxy blocks until the real session is available - but by then the
background init has had a head start (often already complete).

Key changes:
- kernel_runner.py: Add LazySparkSession proxy, _SparkInitState,
  background thread init, thread-safe _write_json for stdout
- persistentExecutor.ts: Handle new 'spark_ready' message type
- utils.ts: Add showSparkReadyNotification, skip INITIALIZING status

https://claude.ai/code/session_01NCzUTPmDaWc5Rwr8xB4Zfu
The setting description referenced the old synchronous Spark init
which could take 15-25s. With deferred initialization, the kernel
starts in 1-2 seconds so the description is updated accordingly.

https://claude.ai/code/session_01NCzUTPmDaWc5Rwr8xB4Zfu
@Hazzng Hazzng force-pushed the claude/databricks-startup-performance-AjokB branch from 97b734b to f6d7d5b Compare April 14, 2026 10:46
Hazzng added 2 commits April 14, 2026 11:48
The LazySparkSession proxy was permanently caching the background init
failure. If the token was expired at startup, every subsequent
spark.sql() raised the cached error even after the user ran
'databricks auth login'. Now _get_session() retries
initialize_spark_session() synchronously on failure, picking up
refreshed tokens from the cache.

https://claude.ai/code/session_01NCzUTPmDaWc5Rwr8xB4Zfu
@Hazzng Hazzng merged commit 5ea85ae into main Apr 14, 2026
6 checks passed
@Hazzng Hazzng deleted the claude/databricks-startup-performance-AjokB branch April 14, 2026 13:15
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.

1 participant