From 6875c44538c75080e879793c9cbcda56d32afc4d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 25 Dec 2025 17:04:35 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20optimize=20file=20content?= =?UTF-8?q?=20extraction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 💡 What: Replaced `cat file | sed | tr` pipeline with direct `tr < file` redirection. 🎯 Why: Reduces process creation overhead (3 processes -> 1 process) and removes a buggy `sed 's// /g'` command that could cause silent failures. 📊 Impact: ~15% speedup in file reading micro-benchmarks (3743ms vs 4421ms for 1000 iterations). 🔬 Measurement: Verified with a custom benchmark script looping over file reads. Existing tests pass. --- benchmark.sh | 26 ++++++++++++++++++++++++++ codepack.sh | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100755 benchmark.sh diff --git a/benchmark.sh b/benchmark.sh new file mode 100755 index 0000000..8b99449 --- /dev/null +++ b/benchmark.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Create a dummy file +echo "This is a test file with some content to simulate reading." > dummy_file.txt + +ITERATIONS=1000 + +echo "Benchmarking original method (cat | sed | tr)..." +start_time=$(date +%s%N) +for ((i=0; i/dev/null | sed 's// /g' 2>/dev/null | tr -cd '\11\12\15\40-\176' 2>/dev/null || echo "") +done +end_time=$(date +%s%N) +duration=$((end_time - start_time)) +echo "Original method took: $((duration/1000000)) ms" + +echo "Benchmarking optimized method (tr < file)..." +start_time=$(date +%s%N) +for ((i=0; i/dev/null || echo "") +done +end_time=$(date +%s%N) +duration=$((end_time - start_time)) +echo "Optimized method took: $((duration/1000000)) ms" + +rm dummy_file.txt diff --git a/codepack.sh b/codepack.sh index 0d8ae2c..8f77854 100755 --- a/codepack.sh +++ b/codepack.sh @@ -851,7 +851,7 @@ extract_files_content() { # Read file content and clean invalid characters local content="" if [[ -r "$file" && -s "$file" ]]; then - content=$(cat "$file" 2>/dev/null | sed 's// /g' 2>/dev/null | tr -cd '\11\12\15\40-\176' 2>/dev/null || echo "") + content=$(tr -cd '\11\12\15\40-\176' < "$file" 2>/dev/null || echo "") fi debug_log "Content length: ${#content}" >&2