@@ -56,6 +56,12 @@ When set, per-message fontification and table decoration are skipped;
5656`pi-coding-agent--postprocess-history-buffer' runs one consolidated pass after
5757all history has been inserted." )
5858
59+ (defvar-local pi-coding-agent--streaming-table-candidate nil
60+ " Non-nil when recent streaming text may contain a markdown pipe table.
61+ Streaming table decoration is comparatively expensive because it queries the
62+ current message with tree-sitter. Most assistant text is not table content, so
63+ we track whether a pipe has appeared since the last decoration attempt and skip
64+ the query when no table can be present." )
5965
6066(defun pi-coding-agent--history-postprocessing-deferred-p ()
6167 " Return non-nil when history display post-processing is currently deferred."
@@ -95,6 +101,7 @@ Note: status is set to `streaming' by the event handler."
95101 (setq pi-coding-agent--line-parse-state 'line-start )
96102 (setq pi-coding-agent--in-code-block nil )
97103 (setq pi-coding-agent--in-thinking-block nil )
104+ (setq pi-coding-agent--streaming-table-candidate nil )
98105 (pi-coding-agent--set-activity-phase " thinking" ))
99106
100107(defun pi-coding-agent--process-streaming-char (char state in-block )
@@ -194,8 +201,14 @@ fontification; tree-sitter re-parses at the C level on each insert."
194201 (goto-char (marker-position pi-coding-agent--streaming-marker))
195202 (insert transformed)
196203 (set-marker pi-coding-agent--streaming-marker (point ))))
197- ; ; After inserting text with completed lines, check for active table
198- (when (string-match-p " \n " delta)
204+ ; ; After inserting text with completed lines, check for active tables only
205+ ; ; if recent streaming text contained a pipe. This avoids a tree-sitter
206+ ; ; table query on every non-table newline in long assistant messages.
207+ (when (string-match-p " |" delta)
208+ (setq pi-coding-agent--streaming-table-candidate t ))
209+ (when (and pi-coding-agent--streaming-table-candidate
210+ (string-match-p " \n " delta))
211+ (setq pi-coding-agent--streaming-table-candidate nil )
199212 (pi-coding-agent--maybe-decorate-streaming-table)))))
200213
201214(defun pi-coding-agent--thinking-insert-position ()
@@ -1144,7 +1157,8 @@ Updates buffer-local state and renders display updates."
11441157 (" text_end"
11451158 ; ; Text block ended — finalize any active table that may have
11461159 ; ; a trailing row without newline (backstop for streaming).
1147- (pi-coding-agent--maybe-decorate-streaming-table))
1160+ (pi-coding-agent--maybe-decorate-streaming-table)
1161+ (setq pi-coding-agent--streaming-table-candidate nil ))
11481162 (" thinking_start"
11491163 (pi-coding-agent--display-thinking-start))
11501164 (" thinking_delta"
0 commit comments