Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent heavy work in maybeCachedCheckingQueue #2371

Merged
merged 1 commit into from
Mar 15, 2025

Conversation

onevcat
Copy link
Owner

@onevcat onevcat commented Mar 15, 2025

This tries to fix #2362

And also try to improve the iterator perform since Swift now has a better & modern API.

And also try to improve the iterator perform since Swift now has a better & modern API
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @onevcat, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request addresses issue #2362 and aims to improve the performance of the iterator within the DiskStorage class. The primary change involves modifying the setupCacheChecking function to prevent heavy work from being performed on the maybeCachedCheckingQueue. Instead of directly populating the maybeCached set within the queue's asynchronous block, the code now retrieves all files from the directory, creates a set from them, and then asynchronously updates maybeCached on the maybeCachedCheckingQueue. This change also moves the initial file system read to a global dispatch queue to avoid blocking the maybeCachedCheckingQueue during initialization.

Highlights

  • Performance Improvement: Moves the potentially heavy file system operation (contentsOfDirectory) to a global dispatch queue to prevent blocking the maybeCachedCheckingQueue.
  • Asynchronous Update: Updates the maybeCached set asynchronously on the maybeCachedCheckingQueue after retrieving the file list.
  • Error Handling: Ensures that even if the file system operation fails, the maybeCached property is properly handled (set to nil) within the maybeCachedCheckingQueue.

Changelog

  • Sources/Cache/DiskStorage.swift
    • Modified setupCacheChecking to perform file system operations on a global dispatch queue.
    • Updated setupCacheChecking to asynchronously update maybeCached on maybeCachedCheckingQueue after retrieving the file list.
    • Ensured error handling within setupCacheChecking updates maybeCached on maybeCachedCheckingQueue.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


In queues of code, where tasks reside,
A heavy load, we must divide.
Async calls, a gentle hand,
To keep the system, smooth and grand.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request aims to prevent heavy work in the maybeCachedCheckingQueue and improve iterator performance with Swift's modern API. The changes involve moving the file enumeration to a background queue and updating the maybeCached set asynchronously. Overall, the changes seem reasonable, but there are a few points to consider.

Summary of Findings

  • Asynchronous Updates to maybeCached: The maybeCached property is now updated asynchronously. Ensure that all accesses to this property are thread-safe and consider the implications of potential race conditions.
  • Error Handling: The error handling logic disables the maybeCached functionality. Consider logging the error for debugging purposes.
  • Queue Usage: The code uses DispatchQueue.global(qos: .default) for file enumeration. Consider using a more specific QoS level if the file enumeration is performance-critical.

Merge Readiness

The changes seem to address the intended issue and improve performance. However, it's crucial to ensure thread safety when accessing maybeCached and consider logging the error in the catch block. I am unable to approve this pull request, and recommend that others review and approve this code before merging. At a minimum, the high severity issues should be addressed before merging.

@onevcat onevcat merged commit 7719aef into master Mar 15, 2025
48 checks passed
@onevcat onevcat deleted the fix/dead-lock-in-cache branch March 15, 2025 06:21
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.

maybeCachedCheckingQueue.sync crash
1 participant