Skip to content

perf: cache mtime of scripts and notebooks#2965

Merged
johanneskoester merged 3 commits intosnakemake:mainfrom
laf070810:script-mtime-caching
Aug 14, 2024
Merged

perf: cache mtime of scripts and notebooks#2965
johanneskoester merged 3 commits intosnakemake:mainfrom
laf070810:script-mtime-caching

Conversation

@laf070810
Copy link
Copy Markdown
Contributor

@laf070810 laf070810 commented Jul 15, 2024

mtime of script or notebook is checked repeatedly when the same rule is wildcard-expanded, causing a lot of os.lstat calls repeated on the same file, which is unnecessary and can be slow on some filesystems.

This PR adds script mtime caching using functools.lru_cache. It can speedup DAG building time.

Related issues: #2920, #2949

QC

  • The PR contains a test case for the changes or the changes are already covered by an existing test case.
  • The documentation (docs/) is updated to reflect the changes or this is not necessary (e.g. if the change does neither modify the language nor the behavior or functionalities of Snakemake).

Summary by CodeRabbit

  • New Features

    • Introduced a utility function to efficiently retrieve and cache the modification time of script files, improving performance.
  • Improvements

    • Enhanced the existing functionality to streamline file modification time checks, leading to cleaner and more maintainable logic.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Aug 14, 2024

Warning

Rate limit exceeded

@johanneskoester has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 15 minutes and 55 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 22d0d0f and e1ac4ba.

Walkthrough

The recent updates to the snakemake/jobs.py file introduce a new utility function, get_script_mtime, which improves the efficiency of retrieving a script's last modification time through caching. This change streamlines the existing logic in the outputs_older_than_script_or_notebook function by replacing direct calls to obtain modification times with the new utility function. The enhancements promote better performance and maintainability without altering the overall functionality.

Changes

File Change Summary
snakemake/jobs.py Added get_script_mtime function with caching via functools.lru_cache. Updated outputs_older_than_script_or_notebook to use this function for modification time retrieval, improving efficiency and maintainability.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@johanneskoester
Copy link
Copy Markdown
Contributor

Very good catch!

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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between e502312 and 22d0d0f.

Files selected for processing (1)
  • snakemake/jobs.py (3 hunks)
Additional context used
Path-based instructions (1)
snakemake/jobs.py (1)

Pattern **/*.py: Do not suggest to add trailing commas.
Do not suggest type annotations for functions that are defined inside of functions or methods.

Ruff
snakemake/jobs.py

92-92: Missing return type annotation for public function get_script_mtime

(ANN201)


92-92: Missing type annotation for function argument path

(ANN001)

Additional comments not posted (1)
snakemake/jobs.py (1)

406-409: Efficient use of get_script_mtime.

The use of get_script_mtime improves the efficiency of the function by caching the script modification times, reducing redundant filesystem checks.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@sonarqubecloud
Copy link
Copy Markdown

@johanneskoester johanneskoester changed the title feat: add script mtime caching perf: cache mtime of scripts and notebooks Aug 14, 2024
@johanneskoester johanneskoester merged commit 405a056 into snakemake:main Aug 14, 2024
johanneskoester pushed a commit that referenced this pull request Aug 14, 2024
🤖 I have created a release *beep* *boop*
---


##
[8.18.0](v8.17.0...v8.18.0)
(2024-08-14)


### Features

* show info on missing metadata
([#3014](#3014))
([e502312](e502312))


### Performance Improvements

* cache mtime of scripts and notebooks
([#2965](#2965))
([405a056](405a056))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Introduced detailed reporting for missing metadata during workflow
execution, enhancing visibility and debugging.
- **Performance Improvements**
- Implemented caching for script and notebook modification times,
improving workflow execution efficiency.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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