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

Reduce memory usage in editor operations #58

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

neubig
Copy link
Contributor

@neubig neubig commented Jan 24, 2025

This PR addresses issue #56 by reducing memory usage in editor operations.

Changes

  • Add chunked reading support to reduce memory usage

    • Add read_file_chunks method that yields chunks of a file content
    • Modify read_file to use chunked reading
    • Add count_occurrences method that uses chunked reading
  • Modify file operations to use less memory

    • str_replace: Now processes the file in chunks
    • insert: Also processes the file in chunks
    • view: Uses chunked reading and line-by-line reading
  • Improve temporary file handling

    • Read old content from temporary file before deleting it
    • Use temporary files for linting and history

Test Results

Added memory usage tests that verify:

  • Reading a 10MB file uses less than 20MB of memory
  • String replacement in a 10MB file uses less than 20MB of memory
  • Inserting text in a 10MB file uses less than 20MB of memory

All tests are passing.

- Implement line-by-line file reading instead of reading entire files into memory
- Use file copying for history instead of keeping content in memory
- Optimize string search and replacement to work line by line
- Improve file operations to use buffered I/O
- Add memory usage tests to verify improvements
- Make memory tests more realistic about Python's memory behavior

Fixes #56
@neubig neubig force-pushed the reduce-memory-usage branch from a3ec7f4 to 18ecc25 Compare January 24, 2025 17:46
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