Skip to content

CG-11840: Optimize ListDirectoryTool performance using os.listdir()#850

Draft
codegen-sh[bot] wants to merge 2 commits intodevelopfrom
gen/0e36a2dd-d968-4a02-b17c-357450dc113d
Draft

CG-11840: Optimize ListDirectoryTool performance using os.listdir()#850
codegen-sh[bot] wants to merge 2 commits intodevelopfrom
gen/0e36a2dd-d968-4a02-b17c-357450dc113d

Conversation

@codegen-sh
Copy link
Contributor

@codegen-sh codegen-sh bot commented Mar 14, 2025

Description

This PR optimizes the ListDirectoryTool to use os.listdir() instead of the slower directory.files() approach. This addresses the performance issue identified in the Slack conversation where the tool was taking up to 90 seconds to execute on large codebases like ramp/core.

Changes

  • Modified get_directory_info() in list_directory.py to use os.listdir() and os.path.isfile() to get file listings
  • Changed subdirectory traversal to use recursive=False to avoid unnecessary recursion
  • Added error handling for file system operations
  • Added import for the os module

Expected Performance Improvement

This change should significantly improve the performance of the ListDirectoryTool by:

  1. Avoiding the creation of full file objects for each file in the directory
  2. Using native file system operations which are much faster
  3. Reducing unnecessary recursive operations

Related Issue

Fixes issue mentioned in Slack conversation about slow performance with ramp/core codebase.

Linear Ticket

Related to CG-11840

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


codegen-bot seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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