Skip to content

Commit

Permalink
Add option to compress large ETS lookup tables
Browse files Browse the repository at this point in the history
Add a configuration setting to compress large ETS lookup tables
(mainly used for code navigation) to consume less memory. Please note,
it will make table operations slower, therefore it might impact
performance of code navigation.

Rational:
In shared environment where many instances of `vscode_erlang` run in
the same time on large code bases, noticeable amount of memory can be
consumed by this extension. In this case turning on the newly created
option `compressLargeEtsTables` might ease the situation.
  • Loading branch information
Kornel Horvath committed Oct 9, 2024
1 parent fd3c98c commit cd3169f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Support for Erlang tools, including rebar3, EUnit and Dialyzer
- `erlang.includePaths` - Include paths are read from rebar.config, and also standard set of paths is used. This setting is for special cases when the default behaviour is not enough
- `erlang.linting` - Enable/disable dynamic validation of opened Erlang source files
- `erlang.codeLensEnabled` - Enable/Disable CodeLens
- `erlang.compressLargeEtsTables` - Enable/disable compression of large ETS lookup tables (mainly used for code navigation) to consume less memory. Please note, it might impact performance.
- `erlang.inlayHintsEnabled` - Enable/Disable InlayHints
- `erlang.verbose` - Activate technical traces for use in the extension development

Expand Down
21 changes: 14 additions & 7 deletions apps/erlangbridge/src/gen_lsp_doc_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,18 @@ as_string(Text) ->
Text.

start_link() ->
safe_new_table(document_contents, set),
safe_new_table(syntax_tree, set),
safe_new_table(dodged_syntax_tree, set),
safe_new_table(references, bag),
safe_new_table(document_inlayhints, set),
%% To save memory let's compress large ETS tables that are always used by
%% primary key basis, never by `match` or `select`.
ExtraEtsOpts =
case init:get_argument(vscode_ets_compressed) of
{ok, [["true"]]} -> [compressed];
_ -> []
end,
safe_new_table(document_contents, set, ExtraEtsOpts),
safe_new_table(syntax_tree, set, ExtraEtsOpts),
safe_new_table(dodged_syntax_tree, set, ExtraEtsOpts),
safe_new_table(references, bag, []),
safe_new_table(document_inlayhints, set, ExtraEtsOpts),
gen_server:start_link({local, ?SERVER}, ?MODULE, [],[]).

init(_Args) ->
Expand Down Expand Up @@ -409,9 +416,9 @@ delete_project_files([File | Files], State) ->
NewState = State#state{project_modules = UpdatedProjectModules},
delete_project_files(Files, NewState).

safe_new_table(Name, Type) ->
safe_new_table(Name, Type, ExtraOpts) ->
case ets:whereis(Name) of
undefined -> ets:new(Name, [Type, named_table, public]);
undefined -> ets:new(Name, [Type, named_table, public | ExtraOpts]);
_ -> Name
end.

Expand Down
1 change: 1 addition & 0 deletions lib/ErlangConfigurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function configurationChanged(): void {
erlangDistributedNode: erlangConf.get("erlangDistributedNode", false),
rebarPath: resolveVariables(erlangConf.get<string>("rebarPath", null)),
codeLensEnabled: erlangConf.get<boolean>('codeLensEnabled', false),
compressLargeEtsTables: erlangConf.get("compressLargeEtsTables", false),
inlayHintsEnabled: erlangConf.get<boolean>('inlayHintsEnabled', false),
debuggerRunMode: erlangConf.get<string>("debuggerRunMode", "Server"),
includePaths: erlangConf.get("includePaths", []),
Expand Down
2 changes: 2 additions & 0 deletions lib/GenericShell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class GenericShell extends EventEmitter {
public erlangPath: string = null;
public erlangArgs : string[] = [];
public erlangDistributedNode: boolean = false;
public compressLargeEtsTables: boolean = false;

//provide IGenericShellConfiguration, in order to avoid dependencies on vscode module (it doesn't works with debugger-adpater)
constructor(logOutput?: ILogOutput, shellOutput?: IShellOutput, erlangConfiguration?: ErlangSettings) {
Expand Down Expand Up @@ -67,6 +68,7 @@ export class GenericShell extends EventEmitter {
}
this.erlangArgs = erlangConfiguration.erlangArgs;
this.erlangDistributedNode = erlangConfiguration.erlangDistributedNode;
this.compressLargeEtsTables = erlangConfiguration.compressLargeEtsTables;
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/erlangSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface ErlangSettings {
includePaths : string[];
linting: boolean;
codeLensEnabled : boolean;
compressLargeEtsTables: boolean;
inlayHintsEnabled: boolean;
verbose: boolean;
debuggerRunMode : string;
Expand Down
5 changes: 5 additions & 0 deletions lib/lsp/ErlangShellLSP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export class ErlangShellLSP extends GenericShell {
"-sname", "vscode_" + listen_port.toString(),
"-setcookie", "vscode_" + listen_port.toString());
}
// Turn on compression of large ETS lookup tables to consume less memory
if (this.compressLargeEtsTables) {
debugStartArgs.push(
"-vscode_ets_compressed", "true");
}
// Use special command line arguments
if (this.erlangArgs) {
debugStartArgs = debugStartArgs.concat(this.erlangArgs)
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
},
"erlang.erlangDistributedNode": {
"type": "boolean",
"description": "Start the Erlang backend in a distributed Erlang node. Could be usefull for extension development. Note, it starts EPMD if not running yet.",
"description": "Start the Erlang backend in a distributed Erlang node. Could be useful for extension development. Note, it starts EPMD if not running yet.",
"default": false
},
"erlang.rebarPath": {
Expand Down Expand Up @@ -221,6 +221,11 @@
"default": false,
"description": "Enable/disable references CodeLens on functions."
},
"erlang.compressLargeEtsTables": {
"type": "boolean",
"description": "Enable/disable compression of large ETS lookup tables (mainly used for code navigation) to consume less memory. Please note, it might impact performance.",
"default": false
},
"erlang.inlayHintsEnabled": {
"type": "boolean",
"default": false,
Expand Down

0 comments on commit cd3169f

Please sign in to comment.