Skip to content

Commit

Permalink
feat(rosetta): propagate max heap size to worker threads (#3002)
Browse files Browse the repository at this point in the history
Worker threads have their own memory limits, which have relatively low
defaults. In order to improve the effectiveness of rosetta, this ensures
all worker threads have the same maximum heap size as the parent process.
  • Loading branch information
RomainMuller authored Sep 28, 2021
1 parent f3e2271 commit 9c7f63e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/jsii-rosetta/lib/commands/extract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as os from 'os';
import * as path from 'path';
import * as ts from 'typescript';
import * as v8 from 'v8';

import { loadAssemblies, allTypeScriptSnippets } from '../jsii/assemblies';
import * as logging from '../logging';
Expand Down Expand Up @@ -210,6 +211,12 @@ async function workerBasedTranslateAll(
): Promise<import('./extract_worker').TranslateResponse> {
return new Promise((resolve, reject) => {
const wrk = new worker.Worker(path.join(__dirname, 'extract_worker.js'), {
resourceLimits: {
// Note: V8 heap statistics are expressed in bytes, so we divide by 1MiB (1,048,576 bytes)
maxOldGenerationSizeMb: Math.ceil(
v8.getHeapStatistics().heap_size_limit / 1_048_576,
),
},
workerData: request,
});
wrk.on('message', resolve);
Expand Down

0 comments on commit 9c7f63e

Please sign in to comment.