Truffle: JavaScript heap out of memory

Created on 22 May 2018  路  4Comments  路  Source: trufflesuite/truffle

  • [x] I've asked for help in the Truffle Gitter before filing this issue.

Issue

when i run truffle complie , i got an error FATAL ERROR: MarkCompactCollector: semi-space copy, fallback in old gen Allocation failed - JavaScript heap out of memory
i know i should change v8 --max-old-space-size ,but i don't know i should change which file,please help me.

Steps to Reproduce

truffle complie

Actual Results

Compiling ./contracts/math.sol...
Compiling ./contracts/token.sol...

<--- Last few GCs --->

[6509:0x39e1a30] 123533 ms: Mark-sweep 1395.5 (1440.7) -> 1395.5 (1448.7) MB, 1289.2 / 0.0 ms allocation failure scavenge might not succeed
[6509:0x39e1a30] 124861 ms: Mark-sweep 1403.6 (1448.7) -> 1403.6 (1456.7) MB, 1306.5 / 0.0 ms allocation failure scavenge might not succeed
[6509:0x39e1a30] 126493 ms: Mark-sweep 1411.2 (1456.7) -> 1411.3 (1461.2) MB, 1625.3 / 0.0 ms allocation failure scavenge might not succeed

<--- JS stacktrace --->
Cannot get stack trace in GC.
FATAL ERROR: MarkCompactCollector: semi-space copy, fallback in old gen Allocation failed - JavaScript heap out of memory
1: node::Abort() [node]
2: 0x121a7ac [node]
3: v8::Utils::ReportOOMFailure(char const, bool) [node]
4: v8::internal::V8::FatalProcessOutOfMemory(char const
, bool) [node]
5: v8::internal::EvacuateNewSpaceVisitor::Visit(v8::internal::HeapObject, int) [node]
6: v8::internal::FullEvacuator::RawEvacuatePage(v8::internal::Page
, long) [node]
7: v8::internal::Evacuator::EvacuatePage(v8::internal::Page
) [node]
8: v8::internal::PageEvacuationTask::RunInParallel() [node]
9: v8::internal::ItemParallelJob::Task::RunInternal() [node]
10: v8::internal::ItemParallelJob::Run() [node]
11: void v8::internal::MarkCompactCollectorBase::CreateAndExecuteEvacuationTasks(v8::internal::MarkCompactCollector, v8::internal::ItemParallelJob, v8::internal::RecordMigratedSlotVisitor, v8::internal::MigrationObserver, long) [node]
12: v8::internal::MarkCompactCollector::EvacuatePagesInParallel() [node]
13: v8::internal::MarkCompactCollector::Evacuate() [node]
14: v8::internal::MarkCompactCollector::CollectGarbage() [node]
15: v8::internal::Heap::MarkCompact() [node]
16: v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
17: v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReas

Environment

  • Operating System: ubuntu 16.04
  • Truffle version (truffle version):v4.1.8
  • node version (node --version):v8.10.0
  • npm version (npm --version): 3.5.2

Most helpful comment

@cgewecke thank you ,it's working for me

All 4 comments

Hi @a186r. Does something like this work?

# Example for `truffle test` where truffle is installed globally
$ which truffle
> /usr/local/bin/truffle
$ node --max-old-space-size=4096 /usr/local/bin/truffle test

@cgewecke thank you ,it's working for me

Sweet!

Something that might help people stumbling upon this issue:

I ran into the same problem with a truffle migrate because I had ~80 files in build/contracts that were each ~25Mb big, so the process ran out of memory when deploying. Using the --max-old-space-size=4096 workaround worked but deploying took a few minutes every time (which quickly got annoying).

What I did was alter the 1_initial_migration.js file so it deletes the ast and legacyAST keys from the contract files which accounted for 95% of the file size and are not necessary for deployment, and deployment times were blazingly fast again (my version requires jq to be installed):

const fs = require("fs");
const child_process = require("child_process");

var Migrations = artifacts.require("./Migrations.sol");

module.exports = function(deployer) {
  deployer.deploy(Migrations);

  const contractFiles = fs.readdirSync("./build/contracts");
  contractFiles.forEach(contractFile => {
    const fullPath = `./build/contracts/${contractFile}`;
    const stdout = child_process.execSync(
      `jq '. | del(.ast, .legacyAST)' ${fullPath}`
    );
    fs.writeFileSync(fullPath, stdout);
  });
  console.log("--- Deleted ASTs");
};
Was this page helpful?
0 / 5 - 0 ratings