-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Comments
Seeing the same behaviour, in a |
Can you provide explicit steps to reproduce? Are you saving the file in VSCode? |
nvm, no longer using zed. |
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. 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}") |
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. |
@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
|
In my case it's log files. I start my application, it makes some logs, usually its size about 100K.
Reopen file changes nothing. Only Zed reloading helps. |
Yup, IIRC re-opening Zed still opened a cached file. soo annoying. |
Check for existing issues
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.
foo.json
in both VSCode and Zed at the same time.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
The text was updated successfully, but these errors were encountered: