⚡ Bolt: optimize synthetic embedding generation#222
Conversation
This commit optimizes the `syntheticVector` generation in `@jeanbot/ai` by: 1. Using the one-shot `crypto.hash` method (Node 22+) instead of `crypto.createHash`. 2. Reducing redundant `normalizeText` calls within the generation loop. Expected Impact: - ~2x speedup in synthetic embedding generation. - Measured improvement from ~7.5ms to ~3.6ms per vector (1536 dimensions). Verification: - Ran `benchmark.ts` to measure execution time and verify determinism. - Ran `pnpm test` to ensure no regressions. Co-authored-by: hackerxj2010 <198651211+hackerxj2010@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What: The optimization implemented
Optimized the
syntheticVectorgeneration in the@jeanbot/aipackage by leveraging the one-shotcrypto.hashfunction available in Node.js 22 and eliminating redundant string normalization operations.🎯 Why: The performance problem it solves
The previous implementation used
crypto.createHash('sha256').update(...).digest()within a loop of 1536 iterations per vector, and performed redundantnormalizeTextcalls. This created unnecessary object instantiation and CPU overhead for a high-frequency operation.📊 Impact: Expected performance improvement
🔬 Measurement: How to verify the improvement
I created a temporary benchmark script that ran 1000 iterations of
syntheticVectorand compared the total duration before and after the change. Determinism was also verified to ensure the output vectors remained identical.PR created automatically by Jules for task 2725135362605627358 started by @hackerxj2010