Skip to content
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

fix(build): Increase maximum wasm memory size from 2GB to 4GB (fixes #25). #38

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

junhaoliao
Copy link
Member

@junhaoliao junhaoliao commented Nov 29, 2024

Description

  1. Set MAXIMUM_MEMORY=4GB in linker flags.

Validation performed

  1. With Node.js v22.9.0, ran perf test 3 times with a version 0.1.0 structured log stream file containing 4.5 million log event entries and observed no significant drop in time performance.
    1. With default 2GB max memory (before): 15.050s, 15.624s, 16.136s
    2. With 4GB max memory (with changes in this PR): 15.312s, 15.180s, 15.050s
      Test code:
    import ModuleInit from "./cmake-build-release/ClpFfiJs-node.js"
    import fs from "node:fs"
    
    const main = async () => {
        const file = fs.readFileSync("./test-4.5M.clp.zst")
    
        console.time("perf")
        const Module = await ModuleInit()
        try {
            const decoder = new Module.ClpStreamReader(new Uint8Array(file), {logLevelKey: "$log_level", timestampKey: "$timestamp"})
            console.log("type:", decoder.getIrStreamType() === Module.IrStreamType.STRUCTURED,
                decoder.getIrStreamType() === Module.IrStreamType.UNSTRUCTURED)
            const numEvents = decoder.deserializeStream()
            console.log(numEvents)
            const results = decoder.decodeRange(0, numEvents, false)
            console.log(results)
        } catch (e) {
            console.error("Exception caught:", e.stack)
        }
        console.timeEnd("perf")
    }
    
    void main()
    
    
  2. Compared sizes before and after the change and found no signication increase in code size.
    1. ClpFfiJs-worker.d.ts: 1.23 KB (1,261 bytes) -> 1.23 KB (1,261 bytes) (unchanged).
    2. ClpFfiJs-worker.js: 25.8 KB (26,427 bytes) -> 27.3 KB (28,007 bytes) (5% increase).
    3. ClpFfiJs-worker.wasm: 742 KB (760,314 bytes) -> 742 KB (760,314 bytes) (unchanged).

Summary by CodeRabbit

  • New Features
    • Introduced a new compile option to enhance memory management for JavaScript execution.
    • Project version updated to 0.3.0, providing users with clarity on the current version.
  • Improvements
    • Default build type set to 'Release' for better performance if not specified by the user.

Copy link

coderabbitai bot commented Nov 29, 2024

Walkthrough

The changes in this pull request focus on updating the CMakeLists.txt file for the clp-ffi-js project. Key modifications include the introduction of a new compile option for Emscripten that sets the maximum memory allocation to 4GB, an update to the CMake policy regarding timestamp handling, and the specification of the project version as 0.3.0. The default build type is set to Release, and the script retains the structure for downloading the Boost library.

Changes

File Change Summary
CMakeLists.txt - Added compile option -sMAXIMUM_MEMORY=4GB.
- Set project version to 0.3.0.
- Updated CMake policy CMP0135 to NEW for version 3.24 or higher.
- Default build type set to Release.
- Retained structure for Boost library download with version 1.85.0.

Possibly related issues


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
CMakeLists.txt (1)

69-73: Clarify memory growth strategy with both ALLOW_MEMORY_GROWTH and MAXIMUM_MEMORY

The configuration uses both -sALLOW_MEMORY_GROWTH and -sMAXIMUM_MEMORY=4GB. Consider documenting the intended memory growth behaviour:

  • Initial memory allocation
  • Growth increments
  • Impact on performance

Consider adding a comment in the CMakeLists.txt explaining the memory configuration strategy.

set(CLP_FFI_JS_COMMON_LINK_OPTIONS
    -fwasm-exceptions
    -sALLOW_MEMORY_GROWTH
    -sEXPORT_ES6
+    # Allow dynamic memory growth up to 4GB to handle large log processing
+    # Initial memory: Default
+    # Growth: On-demand up to maximum
    -sMAXIMUM_MEMORY=4GB
    -sMODULARIZE
    -sWASM_BIGINT
)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 288783a and f2a5eeb.

📒 Files selected for processing (1)
  • CMakeLists.txt (1 hunks)
🔇 Additional comments (2)
CMakeLists.txt (2)

Line range hint 11-16: LGTM: Project version update follows semantic versioning

The project version is properly specified using semantic versioning format.


71-71: Memory increase looks good, but verify low-memory environment compatibility

The increase to 4GB is well-justified by the performance tests and minimal file size impact. However, we should verify the behaviour in low-memory environments.

Let's check if there are any environment-specific memory configurations:

✅ Verification successful

Memory configuration is appropriate for both Node.js and Web Worker environments

The memory settings are well-configured with both ALLOW_MEMORY_GROWTH and a reasonable 4GB maximum limit. This setup supports:

  • Dynamic memory growth as needed
  • Both Node.js and Web Worker environments
  • Large dataset processing (4.5M log events)

The configuration provides flexibility for both high and low-memory scenarios since:

  • Memory growth is allowed, starting small and expanding as needed
  • The 4GB maximum acts as a safety cap, not an initial allocation
  • Both supported environments (node and worker) can handle dynamic memory management
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any memory-related configurations or environment checks
rg -i "memory|heap" --type cmake

Length of output: 206


Script:

#!/bin/bash
# Let's check the context around memory settings and any conditional configurations
rg -B3 -A3 "MAXIMUM_MEMORY|ALLOW_MEMORY_GROWTH" CMakeLists.txt

# Also check for any environment-specific configurations
rg -i "environment|platform|target" CMakeLists.txt

Length of output: 991


Script:

#!/bin/bash
# Let's check what environments are supported
rg -B2 -A2 "CLP_FFI_JS_SUPPORTED_ENVIRONMENTS" CMakeLists.txt

# And check if there are any memory-related configurations in the source files
rg -i "memory|heap" src/ --type cpp

Length of output: 822

@junhaoliao junhaoliao requested a review from davemarco November 29, 2024 08:55
@junhaoliao
Copy link
Member Author

discussed with @davemarco offline and he will review this later in the evening

@davemarco
Copy link
Contributor

Do you want to check that this causes no bugs in firefox/chrome? Normally what i have been doing is adding a "dist" folder to clp-ffi-js repo. Then I add the build files into the dist folder. Then I run
npm install --save /homes/davidmawk/clp-ffi-js-fork in the log viewer repo to get my local clp-ffi-js to run in the log viewer instead of the one on npm.

Copy link
Contributor

@davemarco davemarco left a comment

Choose a reason for hiding this comment

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

see comment above. I am just curious about testing since in docs, they basically warn you against using the feature (https://emscripten.org/docs/tools_reference/settings_reference.html#maximum-memory)

@junhaoliao
Copy link
Member Author

Do you want to check that this causes no bugs in firefox/chrome? Normally what i have been doing is adding a "dist" folder to clp-ffi-js repo. Then I add the build files into the dist folder. Then I run npm install --save /homes/davidmawk/clp-ffi-js-fork in the log viewer repo to get my local clp-ffi-js to run in the log viewer instead of the one on npm.

Right, it was tested working in below browsers:

  • Safari Version 18.0.1 (20619.1.26.31.7) - Mac mini, Apple M1
  • Firefox 133.0 20241125231607 - WSL Ubuntu 2204
  • Microsoft Edge Version 132.0.2957.26 (Official build) stable app, beta channel (64-bit) on Windows

@davemarco
Copy link
Contributor

davemarco commented Dec 5, 2024

For title how about

fix(build): Increase maximum wasm memory size from 2GB to 4GB (fixes #25).

@davemarco
Copy link
Contributor

Also reminder to close #25 manually when you merge this since it is an enhancement and not a bug

@junhaoliao junhaoliao changed the title feat(build): Set MAXIMUM_MEMORY=4GB in linker flags (fixes #25). fix(build): Increase maximum wasm memory size from 2GB to 4GB (fixes #25). Dec 5, 2024
@junhaoliao junhaoliao merged commit 01aa3a5 into y-scope:main Dec 5, 2024
3 checks passed
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