Skip to content

[perf] async/await parallelization - plan loop + chunk batch + file ops#787

Open
jlin53882 wants to merge 4 commits intoCortexReach:masterfrom
jlin53882:async-parallelization-fix
Open

[perf] async/await parallelization - plan loop + chunk batch + file ops#787
jlin53882 wants to merge 4 commits intoCortexReach:masterfrom
jlin53882:async-parallelization-fix

Conversation

@jlin53882
Copy link
Copy Markdown
Contributor

Summary

Add async/await parallelization opportunities analysis with unit test proof.

Unit Test Results

Test Sequential Parallel Speedup
memory-compactor plan loop 943ms 94ms 10.0x
store.ts doFlush chunk 156ms 62ms 2.5x
self-improvement-files ensureFile 94ms 46ms 2.0x

Changes

  • Add est/async-parallel-proof.mjs with parallelization proof tests

Related Issues

Next Steps

This PR adds test verification. Additional code changes:

  1. memory-compactor.ts: parallelize plan loop with Promise.all
  2. store.ts: batch parallel chunk writes
  3. self-improvement-files.ts: parallel file operations

See Issue #785 for detailed recommendations.

Add unit tests to prove async/await parallelization opportunities:
- memory-compactor plan loop: 10x speedup possible
- store.ts doFlush chunk: 2.5x speedup possible
- self-improvement-files ensureFile: 2x speedup possible

Refs: Issue CortexReach#785
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ea1997c7cd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

console.log(`Sequential: ${seqTime.toFixed(0)}ms`);
console.log(`Parallel: ${parTime.toFixed(0)}ms`);
console.log(`Speedup: ${(seqTime / parTime).toFixed(1)}x`);
console.log(seqTime > parTime * 2 ? "✅ ISSUE CONFIRMED" : "❌ No significant difference");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Fail the proof when the speedup threshold is missed

When this script is used as the added unit-test proof, a regression or noisy environment where the parallel path is not faster only prints ❌ No significant difference; the process still exits 0 and the final summary still says all issues were verified. This makes the new proof unable to fail CI or manual validation in the exact scenario it is meant to catch; convert these checks to assertions or set a non-zero exit code on failure.

Useful? React with 👍 / 👎.

- memory-compactor.ts: parallelize plan loop with Promise.all (15.7x speedup)
- self-improvement-files.ts: parallelize file operations (2.0x speedup)
- Add test file with assertions verifying the fixes work

Test results:
- memory-compactor plan loop: 1107ms -> 70ms (15.7x)
- self-improvement-files ensureFile: 93ms -> 48ms (2.0x)

Refs: Issue CortexReach#785
Copy link
Copy Markdown
Contributor

Review finding:

P1: npm test is broken by a malformed script

The updated package.json test script contains && && node --test test/async-parallelization.test.mjs on line 28. That empty command between the two && operators makes the shell fail before the new test can run.

It also appears to drop the previous tail of the test script after test/command-reflection-guard.test.mjs, including test/tier1-counters.test.mjs. Please restore the omitted tests and remove the extra && before this PR lands.

- Add back test/tier1-counters.test.mjs which was dropped during edit
- Fix '&&  &&' extra amp-amp sequence before async-parallelization test

Fixes PR787 test script issue.
@jlin53882
Copy link
Copy Markdown
Contributor Author

✅ 問題已修復(commit 5d8f5f7

感謝維護者指出 package.json test script 的問題。以下是處理的詳細說明:


問題 1:多餘的 && &&(空命令链)

位置: package.json 第 28 行
問題:test/command-reflection-guard.test.mjstest/async-parallelization.test.mjs 之间出现了 && &&(两个 && 运算符之间多了空格与额外 &&),导致 shell 在执行到空命令时立即失败,后面的测试完全不会运行

- ... && node --test test/command-reflection-guard.test.mjs &&  && node --test test/async-parallelization.test.mjs"
+ ... && node --test test/command-reflection-guard.test.mjs && node --test test/tier1-counters.test.mjs && node --test test/async-parallelization.test.mjs"

問題 2:缺少 test/tier1-counters.test.mjs

問題: 在編輯 test script 時,該測試檔案被遺漏,未被列入執行命令。

修復:test/tier1-counters.test.mjs 恢復至正確位置(在 command-reflection-guard.test.mjs 之後、async-parallelization.test.mjs 之前)。


修復驗證

修復後的完整 test script 末尾:

... && node --test test/command-reflection-guard.test.mjs && node --test test/tier1-counters.test.mjs && node --test test/async-parallelization.test.mjs

Commit: 5d8f5f7fix(test): restore tier1-counters and remove extra && in test script
分支: jlinfork/async-parallelization-fix(已推送)

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.

2 participants