perf: Stream filtered events directly to output file for memory efficiency

This commit is contained in:
Paul Gauthier (aider) 2025-03-13 16:03:27 -07:00
parent dfdd6bf533
commit f8642bfd94

View file

@ -33,9 +33,11 @@ def main():
# Read the events # Read the events
events = [json.loads(line) for line in f if line.strip()] events = [json.loads(line) for line in f if line.strip()]
filtered_events = [] # Write the header to the output file
with open(output_file, "w") as f:
f.write(header + "\n")
# Process each event through the terminal emulator # Process each event through the terminal emulator and stream to file
for event in tqdm(events, desc="Processing events"): for event in tqdm(events, desc="Processing events"):
# Process the event in the terminal # Process the event in the terminal
if len(event) >= 3 and event[1] == "o": # Output event if len(event) >= 3 and event[1] == "o": # Output event
@ -46,13 +48,7 @@ def main():
if "Atuin" in display_content: if "Atuin" in display_content:
continue # Skip this event continue # Skip this event
# Keep this event # Write this event directly to the output file
filtered_events.append(event)
# Write the filtered content to the output file
with open(output_file, "w") as f:
f.write(header + "\n")
for event in filtered_events:
f.write(json.dumps(event) + "\n") f.write(json.dumps(event) + "\n")