scratchfoundation / scratchfoundation/scratch-desktop

Terser consumes too much RAM when building, crashing itself

Open
#161 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

developer facing priority 4
Dominant language
JavaScript
Stars
426
Forks
268
Avg merge
16h 6m
Merged PRs (30d)
25

Description

Expected Behavior

Building should not fail with 8GB RAM

Actual Behavior

Building scratch-desktop (npm run dist) on Windows 10, with Core i5 2.1GHz CPU and 8GB RAM, consumes about 3.5GB of RAM during normal webpack process, but it starts to consume more during TerserPlugin execution, causing the build to fail with allocation failure/out-of-memory.

I am not sure how Terser is getting executed though, we use uglifyjs for most optimizations.

Steps to Reproduce

Run npm run dist.

Operating System and Browser

Windows 10
CPU: Intel Core i5 2.1GHz
RAM 8GB
Node.js v12.18.4

Logs
92% chunk asset optimization TerserPlugin
<--- Last few GCs --->

[2776:00000251D5850960]    35610 ms: Mark-sweep 2042.6 (2062.1) -> 2042.8 (2051.4) MB, 579.5 / 0.0 ms  (+ 1433.3 ms in 74 steps since start of marking, biggest step 46.9 ms, walltime since start of marking 2042 ms) (average mu = 0.104, current mu = 0.029)[2776:00000251D5850960]    37543 ms: Mark-sweep 2048.2 (2051.4) -> 2047.6 (2078.1) MB, 1911.3 / 0.0 ms  (average mu = 0.060, current mu = 0.011) allocation failure scavenge might not succeed

<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 00007FF6C03FB49D]
    1: StubFrame [pc: 00007FF6C03FC3CD]
Security context: 0x02fd705c08d1 <JSObject>
    2: /* anonymous */(aka /* anonymous */) [000000154FDBFF41] [C:\s3test\test-desktop\scratch-desktop\node_modules\terser\dist\bundle.min.js:~1] [pc=000003BCE64A76D9](this=0x001382fc04b1 <undefined>)
    3: /* anonymous */(aka /* anonymous */) [000000154FDBF801] [C:\s3test\test-desktop\scratch-desktop\node_modules\ter...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running npm run dist with the reported Node.js 12.18.4 and inspect the build step that invokes TerserPlugin, including the node_modules/terser/dist/bundle.min.js location from the log. Done means the Scratch Desktop build completes without JavaScript heap out-of-memory failure on the reported 8GB Windows environment.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.