Implement Docker image caching for container reuse to improve performance#2
Merged
haesleinhuepf merged 2 commits intoOct 4, 2025
Merged
Conversation
Co-authored-by: haesleinhuepf <12660498+haesleinhuepf@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Reuse containers
Implement Docker image caching for container reuse to improve performance
Oct 4, 2025
Owner
|
I'm curious how the system behaves now when we call generate_and_optimize_code with parameter n_parallel=2 . The prompt should be about saving an empty text file. After this, the code should count the number of txt files. This should obviously always be 1, also in repeated execution. |
haesleinhuepf
requested changes
Oct 4, 2025
haesleinhuepf
left a comment
Owner
There was a problem hiding this comment.
I'm curious how the system behaves now when we call generate_and_optimize_code with parameter n_parallel=2 . The prompt should be about saving an empty text file. After this, the code should count the number of txt files. This should obviously always be 1, also in repeated execution.
haesleinhuepf
approved these changes
Oct 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Previously, each execution of code or notebook created a new Docker container with a unique timestamp-based tag. This meant that every iteration in
generate_code()would rebuild the entire Docker image from scratch, including reinstalling all dependencies, even when they hadn't changed. For workflows with multiple iterations, this resulted in significant wasted time.Solution
This PR implements Docker layer caching by using stable image tags based on a hash of dependencies, and enables reusing a single
CodeExecutorinstance across multiple executions.Key Changes
1. Docker Layer Caching via Stable Tags
sand-bob-{dependencies_hash}instead ofsand-bob-{timestamp}2. Executor Reuse Pattern
executorparameter toexecute(),execute_notebook(), and all code generation functionsCodeExecutorand reuse it across multiple executionsgenerate_and_optimize_code()now automatically creates and reuses a single executor across all iterations3. Backward Compatibility
executorparameter continues to work as beforeexecutorinstancePerformance Impact
Real measurements from tests:
Example Usage
Testing
Added comprehensive test suite (
tests/test_container_reuse.py) with 4 tests:All tests pass successfully.
Impact
This PR directly addresses the issue where
generate_code()was creating new containers in a loop. The same Docker image layers are now efficiently reused across iterations, resulting in 30-60x faster builds for cached executions and significant overall performance improvements in typical workflows.Fixes #[issue number]
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.