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

Zed is caching files? #20872

Open
1 task done
shinebayar-g opened this issue Nov 19, 2024 · 8 comments
Open
1 task done

Zed is caching files? #20872

shinebayar-g opened this issue Nov 19, 2024 · 8 comments
Labels
editor Feedback for code editing, formatting, editor iterations, etc reproducible Verified steps to reproduce included

Comments

@shinebayar-g
Copy link

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

I'm using VSCode & Zed at the same time. Testing it hand by hand. It seems Zed is caching files aggressively.

  1. Open the same file foo.json in both VSCode and Zed at the same time.
  2. Edit the file in VSCode.
  3. Zed doesn't see the change. Usually it sees the change without even closing the active editor tab. But this time it doesn't.
  4. I even tried closing the active editor tab and re-opened the same file from the file tree. But Zed still doesn't see the change.
  5. The only way to see the change was to reload the Zed or restart Zed.

It's not reproducible in small files. The file I was working on was 30MB big json file. So I'm assuming file size may has something to do with it.

Environment

Zed: v0.162.2 (Zed Preview)
OS: macOS 15.1.0
Memory: 16 GiB
Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your Zed.log file to this issue.

Zed.log

@jknlsn
Copy link

jknlsn commented Nov 20, 2024

Seeing the same behaviour, in a .json file just over 2MB

@notpeter
Copy link
Member

notpeter commented Dec 3, 2024

Can you provide explicit steps to reproduce? Are you saving the file in VSCode?
When I save changes to a big JSON file in VSCode Zed immediately picks up the changes.

@shinebayar-g
Copy link
Author

shinebayar-g commented Dec 3, 2024

Sure, I'll try to prepare exact steps to reproduce with sample data.

nvm, no longer using zed.

@jknlsn
Copy link

jknlsn commented Dec 3, 2024

In my case it was a separate script modifying the JSON, that I had open in Zed to monitor/change manually if needed.

I've just tried to write a simple script now to simulate this, but I'm not able to reproduce the exact behaviour, I'm not seeing it currently. The file is similar in size by making a minimum 3000 entries. Ramping the number up to 30000 entries doesn't seem to make a difference.
I don't know if it was to do with any other apps I had open etc, memory pressure, or version of Zed.

Anyway here's the script to give you an idea, just in case it's a starting point.

import json
import random
import string
from pathlib import Path

FIRST_NAMES = ['Emma', 'Liam', 'Olivia', 'Noah', 'Ava', 'Ethan', 'Sophia', 'Mason', 'Isabella', 'William']
LAST_NAMES = ['Smith', 'Johnson', 'Williams', 'Brown', 'Jones', 'Garcia', 'Miller', 'Davis', 'Rodriguez', 'Martinez']
DEPARTMENTS = ['science', 'math', 'history', 'english', 'art']

def generate_random_id():
    return f"{random.choice(DEPARTMENTS)}_{random.choice(LAST_NAMES).lower()}_{random.randint(1000, 9999)}"

def generate_entry():
    first_name = random.choice(FIRST_NAMES)
    last_name = random.choice(LAST_NAMES)
    dept = random.choice(DEPARTMENTS)

    return {
        "name": f"{first_name} {last_name}",
        "class": dept,
        "email": f"{first_name.lower()}.{last_name.lower()}@school.edu",
        "group": f"group_{random.randint(1, 5)}",
        "status": random.choice(['active', 'inactive', 'pending'])
    }

def generate_test_data(filename='test_data.json'):
    data = {}

    if Path(filename).exists():
        with open(filename, 'r') as f:
            data = json.load(f)

    current_count = len(data)
    if current_count < 3000:
        entries_to_add = 3000 - current_count
    else:
        entries_to_add = random.randint(5, 25)
    for _ in range(entries_to_add):
        student_id = generate_random_id()
        while student_id in data:  # Ensure unique ID
            student_id = generate_random_id()
        data[student_id] = generate_entry()

    with open(filename, 'w') as f:
        json.dump(data, f, indent=2)

    return len(data)

if __name__ == "__main__":
    final_count = generate_test_data()
    print(f"Test data generated. Total entries: {final_count}")

@notpeter notpeter added awaiting info Issue that needs more information from the user editor Feedback for code editing, formatting, editor iterations, etc and removed triage labels Dec 3, 2024
@notpeter
Copy link
Member

notpeter commented Dec 3, 2024

If you manage to trigger this behavior again, please see if there's anything of note in the Zed logs.

Pure speculation, but I wonder if there's a race condition where Zed gets notified of a change but before we can read the filename is replaced again. As a result Zed falls into an error state when it stops watching. (pure speculation). I'd be curious whether closing and reopning the tab (cmd-w, cmd-shift-t) brings things back to normal.

Anyways, would love something reproducible so we can dig deeper.

@devzeth devzeth added the reproducible Verified steps to reproduce included label Feb 21, 2025
@devzeth
Copy link
Member

devzeth commented Feb 21, 2025

@notpeter i was able to reproduce it in zed prev 175.1, its not realistic, but vscode can cope with it:

import json
import random
import string
import time
from pathlib import Path
from concurrent.futures import ThreadPoolExecutor

FIRST_NAMES = ['Emma', 'Liam', 'Olivia', 'Noah', 'Ava', 'Ethan', 'Sophia', 'Mason']
LAST_NAMES = ['Smith', 'Johnson', 'Williams', 'Brown', 'Jones', 'Garcia', 'Miller']
DEPARTMENTS = ['science', 'math', 'history', 'english', 'art']

def generate_random_id():
    return f"{random.choice(DEPARTMENTS)}_{random.choice(LAST_NAMES).lower()}_{random.randint(1000, 9999)}"

def generate_entry():
    first_name = random.choice(FIRST_NAMES)
    last_name = random.choice(LAST_NAMES)
    dept = random.choice(DEPARTMENTS)

    return {
        "name": f"{first_name} {last_name}",
        "class": dept,
        "email": f"{first_name.lower()}.{last_name.lower()}@school.edu",
        "group": f"group_{random.randint(1, 5)}",
        "status": random.choice(['active', 'inactive', 'pending'])
    }

def write_data(filename, data):
    """Write data to file with a small random delay"""
    time.sleep(random.uniform(0.001, 0.005))  # Simulate small I/O delays
    with open(filename, 'w') as f:
        json.dump(data, f, indent=2)

def rapid_file_updates(filename='test_data.json', duration=5):
    """Perform rapid file updates for a specified duration"""
    data = {}
    start_time = time.time()
    
    with ThreadPoolExecutor(max_workers=4) as executor:
        while time.time() - start_time < duration:
            # Generate new entry
            student_id = generate_random_id()
            while student_id in data:
                student_id = generate_random_id()
            data[student_id] = generate_entry()
            
            # Submit write task to thread pool
            executor.submit(write_data, filename, data)
            
            # Add a very small delay to prevent complete CPU saturation
            time.sleep(0.001)
            
            # Occasionally read the file to simulate file watching
            if random.random() < 0.1:  # 10% chance to read
                try:
                    with open(filename, 'r') as f:
                        _ = json.load(f)
                except json.JSONDecodeError:
                    print("Race condition detected: Invalid JSON")
                except FileNotFoundError:
                    print("Race condition detected: File not found")

    return len(data)

if __name__ == "__main__":
    test_file = "test_data.json"
    print(f"Starting rapid file updates for 5 seconds...")
    final_count = rapid_file_updates(test_file)
    print(f"Test completed. Final entry count: {final_count}")

First make a test_data.json file next to this script and open it, then execute the above python script, mac temperature goes up to 70-80 degrees, sometimes we have the beachball forever, but there are cases where the current view isn't showing the actual data thats in the json

  • As far as I understand rust and my fast look in to the codebase inside buffer.rs and buffer_store.rs, we don't seem to have any kind of "debounce" or "rate limiting" for reading changes from disk? Do we need this?

@devzeth devzeth removed the awaiting info Issue that needs more information from the user label Feb 21, 2025
@notpeter notpeter removed the bug [core label] label Feb 21, 2025
@BartolomeyKant
Copy link

BartolomeyKant commented Feb 26, 2025

In my case it's log files. I start my application, it makes some logs, usually its size about 100K.
If it's already opened in Zed there a few cases:

  • it never updates
  • it updates after a 5-10 seconds
  • Zed makes a high cpu and memory load and I kill it

Reopen file changes nothing. Only Zed reloading helps.

@shinebayar-g
Copy link
Author

Reopen file changes nothing

Yup, IIRC re-opening Zed still opened a cached file. soo annoying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor Feedback for code editing, formatting, editor iterations, etc reproducible Verified steps to reproduce included
Projects
None yet
Development

No branches or pull requests

5 participants