mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-10 04:22:12 +00:00
While investigating build times noticed that our lambda creation times were increasing linearly with the number of pages which is unexpected since there are mostly shared dependencies. After further investigation it seems we were falling back to our legacy manual `nodeFileTrace` calls in the builder when we shouldn't have been. Also noticed we were still doing the un-necessary reading/calculating for uncompressed lambda sizes which is as discussed previously isn't required and the only limit we need to keep enforcing is the uncompressed size which is a lot less expensive to compute. As a further optimization this adds proper usage of our lstat cache/sema where it wasn't previously and proper parallelizing where applicable. These changes reduce tracing/lambda creation times by 3-5x in larger applications and can fix edge cases where we weren't leveraging our more accurate traces from the build. Before: ```sh Traced Next.js server files in: 444.05ms Created all serverless functions in: 1:36.311 (m:ss.mmm) Collected static files (public/, static/, .next/static): 241.47ms ``` After: ```sh Traced Next.js server files in: 10.4ms Created all serverless functions in: 43.684s Collected static files (public/, static/, .next/static): 250.828ms ```
58 lines
1.5 KiB
JavaScript
58 lines
1.5 KiB
JavaScript
const fs = require('fs-extra');
|
|
const ms = require('ms');
|
|
const path = require('path');
|
|
const { build } = require('../../../../dist');
|
|
const { FileFsRef } = require('@vercel/build-utils');
|
|
|
|
jest.setTimeout(ms('6m'));
|
|
|
|
describe(`${__dirname.split(path.sep).pop()}`, () => {
|
|
it('should normalize routes in build results output', async () => {
|
|
// TODO: remove after bug with edge functions on Windows
|
|
// is resolved upstream in Next.js
|
|
if (process.platform === 'win32') {
|
|
const indexPage = path.join(__dirname, 'pages/index.tsx');
|
|
await fs.writeFile(
|
|
indexPage,
|
|
(
|
|
await fs.readFile(indexPage, 'utf8')
|
|
).replace('runtime: ', '// runtime: ')
|
|
);
|
|
}
|
|
|
|
const files = [
|
|
'index.test.js',
|
|
'next.config.js',
|
|
'package.json',
|
|
'tsconfig.json',
|
|
'pages/api/hello.ts',
|
|
'pages/index.tsx',
|
|
].reduce((filesMap, file) => {
|
|
const fsPath = path.join(__dirname, file);
|
|
const { mode } = fs.statSync(fsPath);
|
|
filesMap[path] = new FileFsRef({ mode, fsPath });
|
|
return filesMap;
|
|
}, {});
|
|
|
|
const { output } = await build({
|
|
config: {
|
|
installCommand: 'yarn',
|
|
},
|
|
entrypoint: 'package.json',
|
|
files,
|
|
meta: {
|
|
skipDownload: true,
|
|
},
|
|
repoRootPath: __dirname,
|
|
workPath: __dirname,
|
|
});
|
|
|
|
expect(output).toHaveProperty('test/api/hello');
|
|
expect(output['test/api/hello'].type).toEqual('EdgeFunction');
|
|
|
|
for (const name in output) {
|
|
expect(output[name].type).not.toBe('Lambda');
|
|
}
|
|
});
|
|
});
|