Skip to content

⚡ Bolt: optimize createDirectory to be async and parallel#2733

Merged
srod merged 1 commit intodevelopfrom
bolt/optimize-createdirectory-async-2804312093143247966
Jan 3, 2026
Merged

⚡ Bolt: optimize createDirectory to be async and parallel#2733
srod merged 1 commit intodevelopfrom
bolt/optimize-createdirectory-async-2804312093143247966

Conversation

@google-labs-jules
Copy link
Copy Markdown
Contributor

@google-labs-jules google-labs-jules bot commented Jan 3, 2026

Optimize createDirectory to be async and parallel.


PR created automatically by Jules for task 2804312093143247966 started by @srod


Summary by cubic

Optimized directory creation in the compression flow by making it async and parallel. This removes blocking I/O and speeds up multi-file runs.

  • Refactors
    • Converted createDirectory to async and replaced mkdirp.sync with mkdirp.
    • Removed fs.statSync; let mkdirp handle existence.
    • Deduplicated target directories and created them in parallel with Promise.all.
    • compress() now awaits directory creation.

Written for commit e38b2ca. Summary will update on new commits.

Summary by CodeRabbit

  • Documentation

    • Added a journal entry template with predefined sections for recording learning and action items.
  • Improvements

    • Enhanced compression process with optimized directory handling for better performance.

✏️ Tip: You can customize this high-level summary in your review settings.

💡 What:
- Converted `createDirectory` in `packages/core/src/compress.ts` to be asynchronous.
- Replaced synchronous `mkdirp.sync` with asynchronous `mkdirp` (v3).
- Implemented parallel directory creation using `Promise.all`.
- Removed blocking `fs.statSync` check (letting `mkdirp` handle existence).
- Updated `compress` function to await the directory creation.

🎯 Why:
- The previous implementation used blocking synchronous I/O (`fs.statSync`, `mkdirp.sync`) inside the main compression flow.
- This could block the event loop, especially when processing multiple files or when filesystem operations are slow.
- Parallel execution of directory creation reduces total setup time.

📊 Impact:
- Non-blocking execution of directory creation.
- Faster setup for multi-file compression tasks involving multiple directories.

🔬 Measurement:
- Verified with existing tests in `packages/core`.
- Code logic ensures no regression in directory creation behavior.
@google-labs-jules
Copy link
Copy Markdown
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jan 3, 2026

⚠️ No Changeset found

Latest commit: e38b2ca

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 3, 2026

📝 Walkthrough

Walkthrough

Adds a journal entry template file and refactors the directory creation logic in compress.ts from synchronous to asynchronous, utilizing parallel directory creation via mkdirp with Set-based deduplication instead of individual sync checks.

Changes

Cohort / File(s) Summary
Template Configuration
.jules/bolt.md
New journal entry template with example structure defining "Learning" and "Action" sections.
Async Refactoring
packages/core/src/compress.ts
Converted createDirectory() from synchronous to async; replaced stat checks and sync creation with Set-based directory collection and parallel mkdirp() invocation. Updated callers to await the promise.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A journal unfolds with learning and care,
While directories now build through the air,
No more waiting for sync's slow refrain—
mkdirp dances, parallel and plain,
Swift as a rabbit, our async terrain!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main optimization: converting createDirectory to async and parallel execution, which is the primary focus of the compress.ts changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

@srod srod marked this pull request as ready for review January 3, 2026 14:42
@srod
Copy link
Copy Markdown
Owner

srod commented Jan 3, 2026

@greptile

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Jan 3, 2026

Greptile Summary

This PR optimizes the createDirectory function in the core compression flow by converting it from synchronous to asynchronous I/O operations. The changes eliminate blocking filesystem calls (fs.statSync, mkdirp.sync) and enable parallel directory creation using Promise.all with automatic deduplication via Set. This improves performance for multi-file compression scenarios by removing synchronous I/O bottlenecks and leveraging parallelism for directory creation.

Changes:

  • Converted createDirectory function from sync to async
  • Removed fs import and directoryExists helper function
  • Replaced synchronous mkdirp.sync with async mkdirp
  • Added directory deduplication using Set<string> to avoid redundant mkdir calls
  • Parallel directory creation using Promise.all
  • Updated caller to await the async operation

Impact: Non-blocking I/O improves throughput for batch compression operations. The deduplication optimization reduces unnecessary filesystem calls when multiple files target the same output directory. All existing tests continue to pass as the public contract remains unchanged.

Confidence Score: 5/5

  • This PR is safe to merge with no identified issues.
  • The implementation is sound and well-tested. The change correctly converts synchronous filesystem operations to async, maintains backward compatibility at the API level, properly handles all edge cases (empty paths, arrays, deduplication), and uses the established async patterns from the codebase. The mkdirp library (v3.0.1) fully supports async operation. All test coverage remains valid and the public function signature change (to async) is properly propagated to the caller with await.
  • No files require special attention

Important Files Changed

Filename Overview
packages/core/src/compress.ts Optimized createDirectory to use async I/O and parallel directory creation. Removed fs.statSync and directoryExists helper, replaced mkdirp.sync with async mkdirp, deduplicates directories using Set, and creates all directories concurrently with Promise.all. Caller properly awaits the async operation.

Sequence Diagram

sequenceDiagram
    participant User
    participant compress
    participant createDirectory
    participant mkdirp
    participant FileSystem

    User->>compress: compress(settings)
    Note over compress: Validate input/output arrays
    
    alt settings.output provided
        compress->>createDirectory: await createDirectory(output)
        
        Note over createDirectory: Extract directory paths<br/>Deduplicate with Set
        
        alt Multiple unique directories
            createDirectory->>mkdirp: Promise.all([mkdirp(dir1), mkdirp(dir2)])
            mkdirp->>FileSystem: Create dir1 (async)
            mkdirp->>FileSystem: Create dir2 (async)
            FileSystem-->>mkdirp: Directories created
            mkdirp-->>createDirectory: All directories created
        else Single directory
            createDirectory->>mkdirp: mkdirp(dir)
            mkdirp->>FileSystem: Create dir (async)
            FileSystem-->>mkdirp: Directory created
            mkdirp-->>createDirectory: Directory ready
        else No directory path
            createDirectory-->>createDirectory: Skip (early return)
        end
        
        createDirectory-->>compress: Ready for file writes
    end
    
    compress->>compress: compressArrayOfFiles() or compressSingleFile()
    compress-->>User: Compressed output
Loading

@srod
Copy link
Copy Markdown
Owner

srod commented Jan 3, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 3, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/core/src/compress.ts (1)

114-114: Fix hardcoded path separator for cross-platform compatibility.

The hardcoded "/" separator will fail on Windows, which uses "\". Use Node's path.dirname() instead.

🔎 Proposed fix using path.dirname()

First, add the import at the top of the file:

import { dirname } from "path";

Then replace line 114:

-        const dirPath = path.substring(0, path.lastIndexOf("/"));
+        const dirPath = dirname(path);
🧹 Nitpick comments (1)
.jules/bolt.md (1)

3-3: Update the example date to reflect current timeframe.

The example entry is dated 2024-05-22, which seems outdated for a PR created in January 2026. Consider updating to a more recent or placeholder date.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b1f227e and e38b2ca.

📒 Files selected for processing (2)
  • .jules/bolt.md
  • packages/core/src/compress.ts
🔇 Additional comments (4)
packages/core/src/compress.ts (4)

49-51: LGTM! Proper async/await integration.

The await ensures directories are created before compression begins, and integrates correctly with the existing async compress function.


98-105: LGTM! Clean async signature and input normalization.

The function correctly handles both string and array inputs with proper early-return guards.


106-106: Excellent optimization with Set deduplication and parallel creation!

The use of a Set to deduplicate directories combined with Promise.all for parallel creation is a solid optimization that aligns perfectly with the PR's goal of removing blocking I/O and improving performance for multi-file operations.

Also applies to: 121-121, 124-127


22-22: mkdirp v3 usage confirmed.

The package.json specifies mkdirp 3.0.1, the import syntax is correct for v3 (import { mkdirp } from "mkdirp"), and the usage properly calls mkdirp as an async function (line 126).

@srod srod merged commit 991dca9 into develop Jan 3, 2026
10 checks passed
@srod srod deleted the bolt/optimize-createdirectory-async-2804312093143247966 branch January 3, 2026 14:50
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.39%. Comparing base (b1f227e) to head (e38b2ca).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2733      +/-   ##
===========================================
- Coverage    99.39%   99.39%   -0.01%     
===========================================
  Files           56       56              
  Lines          993      991       -2     
  Branches       297      296       -1     
===========================================
- Hits           987      985       -2     
  Misses           6        6              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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