-
-
Notifications
You must be signed in to change notification settings - Fork 9
refactor: Extract common Data1D processing logic from sync modifiers #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Created shared processData1D helper function in modifier.ts - Refactored synccomputesmodifier.ts to use shared helper - Refactored syncfixesmodifier.ts to use shared helper - Refactored syncvariablesmodifier.ts to use shared helper - Reduced code duplication from ~125 lines per file to ~10-15 lines - Ensures consistent WASM memory cleanup across all modifiers Fixes #185
|
Cursor Agent can help with this pull request. Just |
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request does a great job of refactoring the common Data1D processing logic into a shared processData1D helper function, significantly reducing code duplication. This is a valuable improvement for maintainability.
I've reviewed the changes and have a few suggestions to further improve the new helper function and its usage, focusing on performance, clarity, and modern TypeScript practices. My comments include a small optimization, removing a redundant check, and fixing a typo in a comment. I've also suggested using object destructuring to make the code in the sync modifiers more idiomatic when updating state from the helper function's result.
- Call data1DNamesWrapper.size() once instead of twice - Remove redundant data1D check in processData1D - Use object destructuring in all three sync modifiers for cleaner code
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request does a great job of refactoring duplicated code into a shared processData1D helper function, which significantly improves maintainability. The logic extraction is well-executed. My review includes a few suggestions to further improve the new helper function's clarity and performance, and to make the calling code in the modifiers more concise.
…ssign - Optimize loop in processData1D: separate j===0 logic and avoid fetching xValues when j>0 - Remove redundant Float32Array type cast (HEAPF32.subarray already returns Float32Array) - Use Object.assign instead of destructuring in sync modifiers for better conciseness
Co-authored-by: anders.hafreager <[email protected]>
- Separate j===0 and j>0 logic for better clarity - Avoid fetching xValues when j>0 (performance improvement) - Store numPoints once to avoid repeated calls - Remove redundant Float32Array type cast
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
The pull request successfully extracts common Data1D processing logic into a shared helper function, significantly reducing code duplication and improving maintainability across SyncComputesModifier, SyncFixesModifier, and SyncVariablesModifier. The changes are well-structured and address the stated objective of reducing redundancy and ensuring consistent WASM memory cleanup. The introduction of the processData1D function is a good refactoring step.
| if (j === 0) { | ||
| const xValuesPointer = lmpData.getXValuesPointer() / 4; | ||
| const xValues = input.wasm.HEAPF32.subarray( | ||
| xValuesPointer, | ||
| xValuesPointer + numPoints, | ||
| ); | ||
| for (let k = lengthBeforeWeStart; k < numPoints; k++) { | ||
| data1D.data.push([xValues[k]]); | ||
| data1D.data[k].push(yValues[k]); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The xValues array is only used when j === 0. However, it is declared inside the loop, which means memory is allocated for it in each iteration, even when it's not used. This could lead to unnecessary memory allocations and potential performance overhead, especially if data1DNamesSize is large. Consider moving the declaration and assignment of xValues outside the loop, or only assign it when j === 0.
const xValuesPointer = lmpData.getXValuesPointer() / 4;
const xValues = input.wasm.HEAPF32.subarray(
xValuesPointer,
xValuesPointer + numPoints,
);
for (let k = lengthBeforeWeStart; k < numPoints; k++) {
data1D.data.push([xValues[k]]);
data1D.data[k].push(yValues[k]);
}
Summary
Fixes #185
Extracts common Data1D processing logic from the three sync modifiers into a shared helper function, reducing code duplication by ~80%.
Changes
processData1D()helper function insrc/modifiers/modifier.tsdata1DNameswrapper and extracting sizeclearPerSynclogicdata1DVectorand extracting x/y values from WASM memoryBenefits
Files Modified
src/modifiers/modifier.ts(added helper function)This pull request contains changes generated by a Cursor Cloud Agent