Skip to content

Avoid Vec+join in jq Replace/Append (DSK-137)#178

Merged
daisuke8000 merged 1 commit into
mainfrom
fix/dsk-137-jq-vec-join
Jul 5, 2026
Merged

Avoid Vec+join in jq Replace/Append (DSK-137)#178
daisuke8000 merged 1 commit into
mainfrom
fix/dsk-137-jq-vec-join

Conversation

@daisuke8000

@daisuke8000 daisuke8000 commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add format_outputs_joined to write jq filter outputs into one String with newline separators.
  • Use it from Replace and Append modes instead of collect::<Vec<_>>().join("\n").

Test plan

  • cargo test -p rustern-core --lib pipeline::jq_evaluate

Made with Cursor

Summary by CodeRabbit

  • Bug Fixes
    • jq の実行結果メッセージの整形を改善し、複数出力を改行区切りでより安定して表示するようになりました。
    • 既存メッセージへの追記時も、出力の連結方法を統一して表示崩れを起こしにくくしました。

Replace collect/join in Replace and Append modes with a single-pass
write into the destination string.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

jq_evaluate.rs において、Val 配列を \n 区切りで文字列化する処理を format_outputs_joined という private ヘルパー関数に抽出しました。QueryMode::Replace および QueryMode::Append の出力生成箇所で、従来のインライン map + join 処理をこのヘルパー呼び出しに置き換えています。あわせて std::fmt::Write の import を追加し、use 文の並びを調整しました。公開APIの変更はありません。

Changes

ファイル 変更概要
crates/rustern-core/src/pipeline/jq_evaluate.rs format_outputs_joined ヘルパー追加、Replace/Append の出力生成をヘルパー呼び出しに置換、import 整理

Sequence Diagram(s)

sequenceDiagram
  participant jq_evaluate
  participant format_outputs_joined
  jq_evaluate->>format_outputs_joined: outputs (&[Val])
  format_outputs_joined-->>jq_evaluate: 結合済み String
  jq_evaluate->>jq_evaluate: ev.message へ設定 (Replace/Append)
Loading

重大度: 低。振る舞いは変更前と等価(同じ結合ロジックの抽出のみ)で、非同期処理・K8s・セキュリティへの影響はなし。

Possibly related issues

  • DSK-137: jq_evaluate.rsQueryMode::Replace/Append 出力整形を Vec+join から文字列ビルダーへ置き換える点で直接一致。
🚥 Pre-merge checks | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning Conventional Commitsの接頭辞がなく、指定形式を満たしていません。 fix: などの Conventional Commits 形式にし、72文字以内で変更内容を具体化してください。
Description check ⚠️ Warning ## 概要/## 変更理由のテンプレートが使われておらず、理由説明が不足しています。 テンプレートどおりに## 概要## 変更理由を追加し、変更の目的と背景を明記してください。

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/rustern-core/src/pipeline/jq_evaluate.rs`:
- Around line 27-36: The hot-path formatter in format_outputs_joined currently
starts with String::new(), which can trigger repeated reallocations as outputs
grow. Update this helper to preallocate the buffer with an appropriate capacity
hint using with_capacity, based on the expected number of Val items and
separators, while keeping the existing join logic in place. Focus the change
inside format_outputs_joined so the per-line allocation behavior in jq_evaluate
is reduced without altering the rendered output.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 180864f5-d536-49ff-ac86-7c84af5c7a75

📥 Commits

Reviewing files that changed from the base of the PR and between 1bcf30e and 4b8747a.

📒 Files selected for processing (1)
  • crates/rustern-core/src/pipeline/jq_evaluate.rs

Comment on lines +27 to +36
fn format_outputs_joined(outputs: &[Val]) -> String {
let mut rendered = String::new();
for (i, v) in outputs.iter().enumerate() {
if i > 0 {
rendered.push('\n');
}
let _ = write!(rendered, "{v}");
}
rendered
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

軽微: 容量事前確保でホットパスの再割当てを削減可能

String::new() は初期容量ゼロのため、要素数が多い場合に複数回の再割当てが発生し得ます。パイプラインのホットパスにおける per-line allocation 最適化が本PRの目的なので、with_capacity によるヒントもついでに検討すると良さそうです。

As per path instructions, "Performance on hot paths (per-line allocations, regex reuse)" が pipeline ディレクトリの重点項目です。

♻️ 提案
 fn format_outputs_joined(outputs: &[Val]) -> String {
-    let mut rendered = String::new();
+    let mut rendered = String::with_capacity(outputs.len() * 16);
     for (i, v) in outputs.iter().enumerate() {
         if i > 0 {
             rendered.push('\n');
         }
         let _ = write!(rendered, "{v}");
     }
     rendered
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fn format_outputs_joined(outputs: &[Val]) -> String {
let mut rendered = String::new();
for (i, v) in outputs.iter().enumerate() {
if i > 0 {
rendered.push('\n');
}
let _ = write!(rendered, "{v}");
}
rendered
}
fn format_outputs_joined(outputs: &[Val]) -> String {
let mut rendered = String::with_capacity(outputs.len() * 16);
for (i, v) in outputs.iter().enumerate() {
if i > 0 {
rendered.push('\n');
}
let _ = write!(rendered, "{v}");
}
rendered
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/rustern-core/src/pipeline/jq_evaluate.rs` around lines 27 - 36, The
hot-path formatter in format_outputs_joined currently starts with String::new(),
which can trigger repeated reallocations as outputs grow. Update this helper to
preallocate the buffer with an appropriate capacity hint using with_capacity,
based on the expected number of Val items and separators, while keeping the
existing join logic in place. Focus the change inside format_outputs_joined so
the per-line allocation behavior in jq_evaluate is reduced without altering the
rendered output.

Source: Path instructions

@daisuke8000
daisuke8000 merged commit 9d4903c into main Jul 5, 2026
3 checks passed
@daisuke8000
daisuke8000 deleted the fix/dsk-137-jq-vec-join branch July 5, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant