mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-20 12:24:59 +00:00
perf: Skip JSON parsing when terminal checking isn't needed
This commit is contained in:
parent
318cc57ffe
commit
ece21315b1
1 changed files with 32 additions and 26 deletions
|
@ -42,36 +42,42 @@ def main():
|
||||||
if not line.strip():
|
if not line.strip():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
event = json.loads(line)
|
# Fast initial check on raw line before JSON parsing
|
||||||
|
raw_line_has_atuin_chars = any(char in line for char in atuin_chars)
|
||||||
|
|
||||||
|
# Only parse JSON if we're checking terminal or need to check
|
||||||
|
if check_terminal or raw_line_has_atuin_chars:
|
||||||
|
event = json.loads(line)
|
||||||
|
|
||||||
|
# For output events, check for potential "Atuin" content
|
||||||
|
if len(event) >= 3 and event[1] == "o":
|
||||||
|
output_text = event[2]
|
||||||
|
|
||||||
# For output events, check for potential "Atuin" content
|
# Only start checking terminal if we found Atuin chars
|
||||||
if len(event) >= 3 and event[1] == "o":
|
if raw_line_has_atuin_chars:
|
||||||
output_text = event[2]
|
check_terminal = True
|
||||||
|
|
||||||
# Fast check: if any letters of "Atuin" are in the output
|
if check_terminal:
|
||||||
if any(char in output_text for char in atuin_chars):
|
stream.feed(output_text)
|
||||||
check_terminal = True
|
|
||||||
|
|
||||||
if check_terminal:
|
# Check if "Atuin" is visible on screen
|
||||||
stream.feed(output_text)
|
atuin_visible = False
|
||||||
|
for display_line in screen.display:
|
||||||
|
if "Atuin" in "".join(display_line):
|
||||||
|
atuin_visible = True
|
||||||
|
break
|
||||||
|
|
||||||
# If we need to check the terminal, do so
|
# Reset flag if Atuin is no longer visible
|
||||||
if check_terminal:
|
if not atuin_visible:
|
||||||
# Check if "Atuin" is visible on screen
|
check_terminal = False
|
||||||
atuin_visible = False
|
else:
|
||||||
for display_line in screen.display:
|
continue # Skip this event if Atuin is visible
|
||||||
if "Atuin" in "".join(display_line):
|
|
||||||
atuin_visible = True
|
# Write event to output file for non-skipped events
|
||||||
break
|
fout.write(line)
|
||||||
|
else:
|
||||||
# Reset flag if Atuin is no longer visible
|
# No need to parse JSON if we're not checking terminal
|
||||||
if not atuin_visible:
|
fout.write(line)
|
||||||
check_terminal = False
|
|
||||||
else:
|
|
||||||
continue # Skip this event if Atuin is visible
|
|
||||||
|
|
||||||
# Write event to output file
|
|
||||||
fout.write(json.dumps(event) + "\n")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue