Skip to content

Memory Settings Guide ​

Optimize BrowserStack Code Quality memory allocation for efficient analysis of large codebases.

Two Analysis Modes — Where to Configure ​

BrowserStack Code Quality supports two distinct analysis modes, and memory must be tuned at the right place for each:

Analysis ModeWhere Analysis RunsWhere to Set Memory
Server (UI / Docker)Inside the Docker container on the serverDocker environment variables (-e ANALYSER_XMX=...)
Remote / CLIOn the machine running the embold-scanner CLI (your laptop or CI/CD agent)Shell environment variables on that machine (e.g., export ANALYSER_XMX=...)

The environment variable names are the same in both modes — the difference is only where you set them.


Overview ​

For repositories with 2+ million lines of code, proper memory configuration is essential for successful analysis. Two key settings control memory usage:

  • Container / Process Memory: Total memory available to the analysis process
  • Analyzer Heap (ANALYSER_XMX): Memory specifically for the analysis engine (JVM heap)

Memory Recommendations ​

Size-Based Configuration ​

Lines of CodeANALYSER_XMXContainer Memory (-m)Recommended RAM
Up to 1 Million-Xmx6g12GB16 GB
2-10 Million-Xmx15g30GB32 GB
10+ Million-Xmx30g60GB64 GB

Memory Allocation Rules ​

  1. Keep ANALYSER_XMX ≤ 70% of container memory
  2. ANALYSER_XMX scales with lines of code (LOC)
  3. ANALYSER_XMX and RISK_XMX are independent settings

Configuration Examples ​

Server Mode — Docker Compose ​

yaml
version: '3.8'
services:
  app:
    image: "browserstack/code-quality:1.9.36.0"
    environment:
      - ANALYSER_XMX=-Xmx15g
      - RISK_XMX=-Xmx1024m
    deploy:
      resources:
        limits:
          memory: 30G

Server Mode — Docker Run ​

bash
docker run -m 30GB -d \
  -e ANALYSER_XMX=-Xmx15360m \
  -e RISK_XMX=-Xmx1024m \
  -p 3000:3000 \
  --name BrowserStackCodeQuality \
  [other options] \
  browserstack/code-quality:1.9.36.0

CLI / Remote Analysis Mode ​

When running the embold-scanner CLI directly (on your machine or a CI/CD agent), set the environment variable in your shell before executing the scan:

bash
# Set analyzer heap size for CLI analysis
export ANALYSER_XMX=-Xmx8g

# Then run the scanner as usual
./browserstack-codequality-scanner/bin/embold-scanner analyse \
  -u https://demo.embold.io \
  -t $EMBOLD_TOKEN \
  -r {YOUR_REPO_UID} \
  -c ./repository-configuration.json

In a CI/CD pipeline (e.g., GitHub Actions, Jenkins, GitLab CI), set it as a pipeline environment variable:

yaml
# GitHub Actions / GitLab CI example
env:
  ANALYSER_XMX: "-Xmx8g"
groovy
// Jenkinsfile example
environment {
    ANALYSER_XMX = '-Xmx8g'
}

Note: For CLI mode there is no container memory limit (-m). Ensure the machine or CI/CD agent has enough physical RAM to accommodate the heap size you configure.

Memory Distribution Guidelines ​

Analyzer Memory as % of Container Memory ​

Repository SizeAnalyzer Memory %
< 1M LOC35-37%
1-3M LOC40-42%
3-5M LOC50-55%

Memory Consumers ​

Primary consumers of container memory:

  • Analysis Engine: 50-70% (configured via ANALYSER_XMX)
  • UI Services: 15-20%
  • Controller Processes: 10-15%
  • Database Operations: 5-10%

Optimization Strategies ​

For Complex Codebases ​

High code duplication or mixed languages may require:

  • 20-30% more memory than standard recommendations
  • Additional monitoring during initial scans
  • Iterative tuning based on actual performance

Performance Monitoring ​

bash
# Monitor container memory usage
docker stats BrowserStackCodeQuality

# Check for memory pressure in logs
docker logs BrowserStackCodeQuality | grep -i "memory\|heap\|gc"

Troubleshooting ​

Out of Memory Errors ​

Symptoms:

  • Analysis fails with heap space errors
  • Container restarts during analysis
  • Slow performance or timeouts

Solutions:

  1. Increase ANALYSER_XMX (ensure < 70% of container memory)
  2. Increase container memory limit (-m parameter)
  3. Enable multi-threaded execution with appropriate memory
  4. Use remote scanning for very large repositories

Memory Optimization Tips ​

  1. Start with recommendations and adjust based on performance
  2. Monitor first scan closely and tune accordingly
  3. Use SSD storage to reduce memory pressure from I/O
  4. Consider remote scanning for repositories > 10M LOC
  5. Enable garbage collection logging for detailed analysis

Advanced Configuration ​

Remote Scanning for Large Repositories ​

For repositories exceeding memory capacity:

bash
# Enable remote scan mode
-e EMB_REMOTE_SCAN=true
-e EMB_REMOTE_SCAN_STRICT=true  # For C++ accuracy

Monitoring and Alerts ​

bash
# Set memory usage alerts
docker run --memory=30g --oom-kill-disable=false \
  [other options]

Environment Variables Reference ​

VariableWhere It AppliesPurposeExample
ANALYSER_XMXServer (Docker) & CLIAnalysis engine heap size-Xmx15g
RISK_XMXServer (Docker)Risk calculation heap size-Xmx1024m
EMB_ANALYSER_THREADSServer (Docker) & CLIAnalysis thread count8
EMB_PARSER_THREADSServer (Docker) & CLIJava parser thread count4
EMB_REMOTE_SCANServer (Docker)Enable remote scanningtrue