Skip to content

Commit 09c8ff9

Browse files
authored
refactor(v8): cache new V8 version during major update (#1116)
After updating the V8 tree, we currently re-fetch the new V8 version from the filesystem several times during various tasks. Instead, we can cache it in the same way that we do the existing version. Updates `getCurrentV8Version()` to a generic task that accepts a label for the version, either 'current' or 'new', from which the context property name is derived.
1 parent 10c6f35 commit 09c8ff9

8 files changed

Lines changed: 17 additions & 26 deletions

File tree

lib/update-v8/applyNodeChanges.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import path from 'node:path';
22

33
import {
4-
getNodeV8Version,
54
filterForVersion,
65
replaceGitignore,
76
removeDirectory
@@ -18,8 +17,7 @@ export default function applyNodeChanges() {
1817
return {
1918
title: 'Apply Node-specific changes',
2019
task: async(ctx, task) => {
21-
const v8Version = await getNodeV8Version(ctx.nodeDir);
22-
const list = filterForVersion(nodeChanges, v8Version);
20+
const list = filterForVersion(nodeChanges, ctx.newVersion);
2321
return task.newListr(list.map((change) => change.task()));
2422
}
2523
};

lib/update-v8/backport.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ListrEnquirerPromptAdapter } from '@listr2/prompt-adapter-enquirer';
88

99
import { shortSha } from '../utils.js';
1010

11-
import { getCurrentV8Version } from './common.js';
11+
import { getV8Version } from './common.js';
1212
import { forceRunAsync } from '../run.js';
1313

1414
export async function checkOptions(options) {
@@ -28,7 +28,7 @@ export async function checkOptions(options) {
2828

2929
export function doBackport(options) {
3030
const todo = [
31-
getCurrentV8Version(),
31+
getV8Version('current'),
3232
generatePatches()
3333
];
3434

lib/update-v8/commitUpdate.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import { getNodeV8Version } from './util.js';
2-
31
export default function commitUpdate() {
42
return {
53
title: 'Commit V8 update',
64
task: async(ctx) => {
7-
const newV8Version = await getNodeV8Version(ctx.nodeDir);
85
await ctx.execGitNode('add', ['deps/v8']);
96
const moreArgs = [];
107
let message;
@@ -15,9 +12,9 @@ export default function commitUpdate() {
1512
'-m',
1613
`Refs: https://github.com/v8/v8/compare/${prev}...${next}`
1714
);
18-
message = `deps: patch V8 to ${newV8Version}`;
15+
message = `deps: patch V8 to ${ctx.newVersion}`;
1916
} else {
20-
message = `deps: update V8 to ${newV8Version}`;
17+
message = `deps: update V8 to ${ctx.newVersion}`;
2118
}
2219
await ctx.execGitNode('commit', ['-m', message, ...moreArgs]);
2320
},

lib/update-v8/common.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { promises as fs } from 'node:fs';
33

44
import { getNodeV8Version } from './util.js';
55

6-
export function getCurrentV8Version() {
6+
export function getV8Version(label) {
77
return {
8-
title: 'Get current V8 version',
8+
title: `Get ${label} V8 version`,
99
task: async(ctx) => {
10-
ctx.currentVersion = await getNodeV8Version(ctx.nodeDir);
10+
ctx[`${label}Version`] = await getNodeV8Version(ctx.nodeDir);
1111
}
1212
};
1313
};

lib/update-v8/deps.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { forceRunAsync } from '../run.js';
66
import {
77
addToGitignore,
88
filterForVersion,
9-
getNodeV8Version,
109
removeDirectory,
1110
replaceGitignore,
1211
} from './util.js';
@@ -54,13 +53,12 @@ export default function updateV8Deps() {
5453
return {
5554
title: 'Update V8 DEPS',
5655
task: async(ctx, task) => {
57-
const newV8Version = await getNodeV8Version(ctx.nodeDir);
58-
const repoPrefix = newV8Version.majorMinor >= 86 ? '' : 'v8/';
56+
const repoPrefix = ctx.newVersion.majorMinor >= 86 ? '' : 'v8/';
5957
const deps = filterForVersion(v8Deps.map((v8Dep) => ({
6058
...v8Dep,
6159
repo: `${repoPrefix}${v8Dep.repo}`,
6260
path: v8Dep.repo
63-
})), newV8Version);
61+
})), ctx.newVersion);
6462
if (deps.length === 0) return;
6563
const depsTable = await readDeps(ctx.nodeDir);
6664
const subtasks = [];

lib/update-v8/majorUpdate.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'node:path';
22

3-
import { getCurrentV8Version } from './common.js';
3+
import { getV8Version } from './common.js';
44
import updateV8Deps from './deps.js';
55
import {
66
removeDirectory,
@@ -14,10 +14,11 @@ export default function majorUpdate() {
1414
title: 'Major V8 update',
1515
task: (ctx, task) => {
1616
return task.newListr([
17-
getCurrentV8Version(),
17+
getV8Version('current'),
1818
checkoutBranch(),
1919
removeDepsV8(),
2020
cloneLocalV8(),
21+
getV8Version('new'),
2122
removeDepsV8Git(),
2223
addDepsV8(),
2324
updateV8Deps(),

lib/update-v8/minorUpdate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'node:path';
22
import { promises as fs } from 'node:fs';
33

4-
import { getCurrentV8Version } from './common.js';
4+
import { getV8Version } from './common.js';
55
import { isVersionString } from './util.js';
66
import { forceRunAsync } from '../run.js';
77

@@ -10,7 +10,7 @@ export default function minorUpdate() {
1010
title: 'Minor V8 update',
1111
task: (ctx, task) => {
1212
return task.newListr([
13-
getCurrentV8Version(),
13+
getV8Version('current'),
1414
getLatestV8Version(),
1515
doMinorUpdate()
1616
]);

lib/update-v8/updateVersionNumbers.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import path from 'node:path';
22
import { promises as fs } from 'node:fs';
33

4-
import { getNodeV8Version } from './util.js';
5-
64
export default function updateVersionNumbers() {
75
return {
86
title: 'Update version numbers',
@@ -16,10 +14,9 @@ function bumpNodeModule() {
1614
return {
1715
title: 'Bump NODE_MODULE_VERSION',
1816
task: async(ctx) => {
19-
const v8Version = await getNodeV8Version(ctx.nodeDir);
2017
const newModuleVersion = await updateModuleVersionRegistry(
2118
ctx.nodeDir,
22-
v8Version,
19+
ctx.newVersion,
2320
ctx.nodeMajorVersion
2421
);
2522
await updateModuleVersion(ctx.nodeDir, newModuleVersion);
@@ -33,7 +30,7 @@ function bumpNodeModule() {
3330
'-m',
3431
getCommitTitle(newModuleVersion),
3532
'-m',
36-
getCommitBody(v8Version)
33+
getCommitBody(ctx.newVersion)
3734
]
3835
);
3936
},

0 commit comments

Comments
 (0)