Skip to content

Commit

Permalink
Merge pull request #494 from lukecotter/perf-code-splitting-faster-load
Browse files Browse the repository at this point in the history
perf: code splitting for faster extension load
  • Loading branch information
lcottercertinia authored Mar 13, 2024
2 parents 31180b6 + 4cfb323 commit 7be1c25
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 40 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- Faster Extension startup time, roughly 12 times faster and starts up time is less than 10ms.

## [1.14.1] - 2024-03-01

### Fixed
Expand Down
5 changes: 4 additions & 1 deletion lana/src/salesforce/codesymbol/SymbolFinder.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/*
* Copyright (c) 2020 Certinia Inc. All rights reserved.
*/
import { Workspaces, type Workspace } from '@apexdevtools/apex-ls';
import { type Workspace } from '@apexdevtools/apex-ls';

import { VSWorkspace } from '../../workspace/VSWorkspace.js';

export class SymbolFinder {
async findSymbol(workspaces: VSWorkspace[], symbol: string): Promise<string[]> {
// Dynamic import for code splitting. Improves performance by reducing the amount of JS that is loaded and parsed at the start.
// eslint-disable-next-line @typescript-eslint/naming-convention
const { Workspaces } = await import('@apexdevtools/apex-ls');
const paths = [];
for (const ws of workspaces) {
const apexWs = Workspaces.get(ws.path());
Expand Down
10 changes: 7 additions & 3 deletions lana/src/salesforce/logs/GetLogFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
* Copyright (c) 2020 Certinia Inc. All rights reserved.
*/

import { AuthHelper } from '@apexdevtools/sfdx-auth-helper';
import { LogService } from '@salesforce/apex-node';

export class GetLogFile {
static async apply(wsPath: string, logDir: string, logId: string): Promise<void> {
// Dynamic import for code splitting. Improves performance by reducing the amount of JS that is loaded and parsed at the start.
// eslint-disable-next-line @typescript-eslint/naming-convention
const { AuthHelper } = await import('@apexdevtools/sfdx-auth-helper');

const ah = await AuthHelper.instance(wsPath);
const connection = await ah.connect(await ah.getDefaultUsername());

if (connection) {
// Dynamic import for code splitting. Improves performance by reducing the amount of JS that is loaded and parsed at the start.
// eslint-disable-next-line @typescript-eslint/naming-convention
const { LogService } = await import('@salesforce/apex-node');
await new LogService(connection).getLogs({ logId: logId, outputDir: logDir });
}
return new Promise((resolve) => resolve());
Expand Down
9 changes: 7 additions & 2 deletions lana/src/salesforce/logs/GetLogFiles.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
/*
* Copyright (c) 2020 Certinia Inc. All rights reserved.
*/
import { AuthHelper } from '@apexdevtools/sfdx-auth-helper';
import { LogService, type LogRecord } from '@salesforce/apex-node';
import { type LogRecord } from '@salesforce/apex-node';

export class GetLogFiles {
static async apply(wsPath: string): Promise<LogRecord[]> {
// Dynamic import for code splitting. Improves performance by reducing the amount of JS that is loaded and parsed at the start.
// eslint-disable-next-line @typescript-eslint/naming-convention
const { AuthHelper } = await import('@apexdevtools/sfdx-auth-helper');
const ah = await AuthHelper.instance(wsPath);
const connection = await ah.connect(await ah.getDefaultUsername());

if (connection) {
// Dynamic import for code splitting. Improves performance by reducing the amount of JS that is loaded and parsed at the start.
// eslint-disable-next-line @typescript-eslint/naming-convention
const { LogService } = await import('@salesforce/apex-node');
return new LogService(connection).getLogRecords();
}
return [];
Expand Down
17 changes: 9 additions & 8 deletions log-viewer/modules/soql/SOQLParser.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
/*
* Copyright (c) 2022 Certinia Inc. All rights reserved.
*/
import { type QueryContext } from '@apexdevtools/apex-parser';
import {
ApexLexer,
ApexParser,
CaseInsensitiveInputStream,
type QueryContext,
} from '@apexdevtools/apex-parser';
import {
CharStreams,
CommonTokenStream,
type ANTLRErrorListener,
type RecognitionException,
type Recognizer,
Expand Down Expand Up @@ -78,6 +71,14 @@ export class SOQLTree {

export class SOQLParser {
async parse(query: string): Promise<SOQLTree> {
// Dynamic import for code splitting. Improves performance by reducing the amount of JS that is loaded and parsed at the start.
// eslint-disable-next-line @typescript-eslint/naming-convention
const { ApexLexer, ApexParser, CaseInsensitiveInputStream } = await import(
'@apexdevtools/apex-parser'
);
// Dynamic import for code splitting. Improves performance by reducing the amount of JS that is loaded and parsed at the start.
// eslint-disable-next-line @typescript-eslint/naming-convention
const { CharStreams, CommonTokenStream } = await import('antlr4ts');
const lexer = new ApexLexer(new CaseInsensitiveInputStream(CharStreams.fromString(query)));
const tokens = new CommonTokenStream(lexer);
const parser = new ApexParser(tokens);
Expand Down
51 changes: 25 additions & 26 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ import copy from 'rollup-plugin-copy';
import { minifyHTML } from 'rollup-plugin-minify-html';
import nodePolyfills from 'rollup-plugin-polyfill-node';
import postcss from 'rollup-plugin-postcss';
import {
defineRollupSwcMinifyOption,
defineRollupSwcOption,
minify,
swc,
} from 'rollup-plugin-swc3';
import { defineRollupSwcOption, swc } from 'rollup-plugin-swc3';

const production = process.env.NODE_ENV === 'production';
console.log('Package mode:', production ? 'production' : 'development');
Expand All @@ -20,9 +15,11 @@ export default [
input: './lana/src/Main.ts',
output: {
format: 'cjs',
file: './lana/out/Main.js',
dir: './lana/out',
chunkFileNames: 'lana-[name].js',
sourcemap: false,
},

external: ['vscode'],
plugins: [
nodeResolve({ preferBuiltins: true, dedupe: ['@salesforce/core'] }),
Expand All @@ -33,17 +30,18 @@ export default [
include: /\.[mc]?[jt]sx?$/,
exclude: 'node_modules',
tsconfig: production ? './lana/tsconfig.json' : './lana/tsconfig-dev.json',
jsc: { transform: { useDefineForClassFields: false } },
jsc: {
minify: {
compress: production,
mangle: production
? {
keep_classnames: true,
}
: false,
},
},
}),
),
production &&
minify(
defineRollupSwcMinifyOption({
// swc's minify option here
mangle: true,
compress: true,
}),
),
],
},
{
Expand All @@ -66,22 +64,23 @@ export default [
include: /\.[mc]?[jt]sx?$/,
exclude: 'node_modules',
tsconfig: production ? './log-viewer/tsconfig.json' : './log-viewer/tsconfig-dev.json',
jsc: { transform: { useDefineForClassFields: false } },
jsc: {
transform: { useDefineForClassFields: false },
minify: {
compress: production,
mangle: production
? {
keep_classnames: true,
}
: false,
},
},
}),
),
postcss({
extensions: ['.css', '.scss'],
minimize: true,
}),
production &&
minify(
defineRollupSwcMinifyOption({
// swc's minify option here
mangle: true,
compress: true,
module: true,
}),
),
minifyHTML({
targets: [
{
Expand Down

0 comments on commit 7be1c25

Please sign in to comment.