Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow Performance and Huge Memory Usage! #44

Closed
BanjoCam opened this issue Apr 19, 2021 · 23 comments
Closed

Slow Performance and Huge Memory Usage! #44

BanjoCam opened this issue Apr 19, 2021 · 23 comments

Comments

@BanjoCam
Copy link

Hi there,

Thank you so much for making this plugin. I have installed the latest version. On Windows 10.

When I use the VSCode version of the plugin, it loads to about 500MB ram, and works great. When I load the exact same project in Sublime, the Node instance goes up to about 3 GB of ram. It takes a long time to get to this point and the plugin more or less doesn't work until then (and is variably unresponsive afterwards). I checked the output logs in both software and I think it may have something to do with how the plugin is indexing files. In VSCode:

SnapshotManager File Statistics:
Project files: 0
Svelte files: 20
From node_modules: 944
Total: 964

The same project in Svelte (and this may still be climbing, I got impatient)
LSP-svelte: SnapshotManager File Statistics:
LSP-svelte: Project files: 0
LSP-svelte: Svelte files: 21
LSP-svelte: From node_modules: 7869
LSP-svelte: Total: 7892

I feel like there must be some sort of file exclusion filter turned off or something. I also don't know what counts as a "Svelte file" but all of the .svelte and .js files in my SRC folder count up to 20. 21 is only if a CSS file is included. I tried copying over the VScode version of the various node_modules folder in the plugin. I also tried copying over the LSP svelte settings from VScode. Nothing made a difference and I don't think I'm smart enough to go further than that!

Thanks for any help you can provide!

@ghost
Copy link

ghost commented Apr 20, 2021

@BanjoCam, hello! I'll check, but that could be related not with the plugin, but with Sublime Text. Can you provide what version of the Sublime Text do you use? Also, please, paste your Sublime Text settings.

@BanjoCam
Copy link
Author

BanjoCam commented Apr 20, 2021

Thanks for the reply!
FYI, I also tested with ST4 on a Mac, and it had incredibly low RAM usage (compared to VSCode or ST4 on Windows) and worked as expected (and super snappy).

I am running the Dev build version 4102.

My sublime settings:

{  
	"auto_complete_commit_on_tab": true,  
	"auto_complete_cycle": true,  
	"auto_complete_selector": "source, text",  
	"auto_complete_with_fields": true,  
	"color_scheme": "Packages/Materialize/schemes/Material One Dark.tmTheme",  
	"font_face": "Fira Code",  
	"font_size": 12,  
	"highlight_line": true,  
	"highlight_modified_tabs": true,  
	"ignored_packages":  
	[  
		"Markdown",  
		"Six",  
		"Vintage",  
		"Vintageous",  
	],  
	"line_padding_bottom": 0,  
	"neovintageous_build_version": 11100,  
	"new_window_settings":  
	{  
		"menu_visible": false,  
	},  
	"relative_line_numbers": true,  
	"rulers":  
	[  
		80  
	],  
	"shift_tab_unindent": true,  
	"swallow_startup_errors": true,  
	"theme": "Adaptive.sublime-theme",  
	"trim_trailing_white_space_on_save": true,  
	"vintage_start_in_command_mode": true,  
	"vintageous_use_ctrl_keys": false,  
	"vintageous_use_super_keys": null,  
}

(I have nothing set for LSP or LSP-Svelte settings)

When I opened Sublime to get you these settings, it still had my Svelte project open. Here is a picture of my task manager (the RAM value was still climbing, and after 2 minutes, it still had not highlighted an intention error I put in my Svelte code):

image

Closing that project and opening a python one:

image

Thanks!

@rchl
Copy link
Member

rchl commented Apr 20, 2021

Does your project have svelte.config.js?

@BanjoCam
Copy link
Author

Just checked - I don't have one.

@rchl
Copy link
Member

rchl commented Apr 20, 2021

Please post the full log from the server (both for ST and VSCode).

@BanjoCam
Copy link
Author

Sublime (note that the log is still growing but it's mainly just repeating the same things). I removed my name/the project name from the logs.

LSP-svelte: Initialize language server at  file:///C:/Users/**redacted project directory**
LSP-svelte: No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
LSP-svelte: Using svelte-preprocess v4.6.9 from C:\Users\**redacted**\AppData\Local\Sublime Text 3\Package Storage\LSP-svelte\14.16.0\server\node_modules\svelte-preprocess
LSP-svelte: Initialize new ts service at
LSP-svelte: Trying to load configs for
LSP-svelte: No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
LSP-svelte: Using svelte-preprocess v4.6.9 from C:\Users\**redacted**\AppData\Local\Sublime Text 3\Package Storage\LSP-svelte\14.16.0\server\node_modules\svelte-preprocess
LSP-svelte: SnapshotManager File Statistics:
LSP-svelte: Project files: 0
LSP-svelte: Svelte files: 0
LSP-svelte: From node_modules: 0
LSP-svelte: Total: 0
LSP-svelte: Using Svelte v3.24.0 from c:\Users\**redacted project directory**\node_modules\svelte\compiler
LSP-svelte: No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
LSP-svelte: Using svelte-preprocess v4.6.9 from C:\Users\**redacted**\AppData\Local\Sublime Text 3\Package Storage\LSP-svelte\14.16.0\server\node_modules\svelte-preprocess
LSP-svelte: No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
LSP-svelte: Using svelte-preprocess v4.6.9 from C:\Users\**redacted**\AppData\Local\Sublime Text 3\Package Storage\LSP-svelte\14.16.0\server\node_modules\svelte-preprocess
LSP-svelte: Using Svelte v3.24.0 from c:\Users\**redacted project directory**\node_modules\svelte\compiler
LSP-svelte: Using Svelte v3.24.0 from c:\Users\**redacted project directory**\node_modules\svelte\compiler
LSP-svelte: SnapshotManager File Statistics:
LSP-svelte: Project files: 0
LSP-svelte: Svelte files: 18
LSP-svelte: From node_modules: 2969
LSP-svelte: Total: 2991
LSP-svelte: Using Svelte v3.24.0 from c:\Users\**redacted project directory**\node_modules\svelte\compiler
LSP-svelte: SnapshotManager File Statistics:
LSP-svelte: Project files: 0
LSP-svelte: Svelte files: 18
LSP-svelte: From node_modules: 5861
LSP-svelte: Total: 5883
LSP-svelte: No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
LSP-svelte: Using svelte-preprocess v4.6.9 from C:\Users\**redacted**\AppData\Local\Sublime Text 3\Package Storage\LSP-svelte\14.16.0\server\node_modules\svelte-preprocess
LSP-svelte: No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
LSP-svelte: Using svelte-preprocess v4.6.9 from C:\Users\**redacted**\AppData\Local\Sublime Text 3\Package Storage\LSP-svelte\14.16.0\server\node_modules\svelte-preprocess
LSP-svelte: Using Svelte v3.24.0 from c:\Users\**redacted project directory**\node_modules\svelte\compiler
LSP-svelte: Using Svelte v3.24.0 from c:\Users\**redacted project directory**\node_modules\svelte\compiler
LSP-svelte: SnapshotManager File Statistics:
LSP-svelte: Project files: 0
LSP-svelte: Svelte files: 21
LSP-svelte: From node_modules: 7049
LSP-svelte: Total: 7071
LSP-svelte: SnapshotManager File Statistics:
LSP-svelte: Project files: 0
LSP-svelte: Svelte files: 21
LSP-svelte: From node_modules: 7787
LSP-svelte: Total: 7809
LSP-svelte: SnapshotManager File Statistics:
LSP-svelte: Project files: 0
LSP-svelte: Svelte files: 21
LSP-svelte: From node_modules: 8148
LSP-svelte: Total: 8170
LSP-svelte: Using Svelte v3.24.0 from c:\Users\**redacted project directory**\node_modules\svelte\compiler

VSCode:

Initialize language server at  file:///c%3A/**redacted project folder**
No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
Using svelte-preprocess v4.6.9 from c:\Users\**redacted**\.vscode\extensions\svelte.svelte-vscode-104.9.1\node_modules\svelte-preprocess
Initialize new ts service at  
Trying to load configs for 
No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
Using svelte-preprocess v4.6.9 from c:\Users\**redacted**\.vscode\extensions\svelte.svelte-vscode-104.9.1\node_modules\svelte-preprocess
SnapshotManager File Statistics:
Project files: 0
Svelte files: 0
From node_modules: 0
Total: 0
No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
Using svelte-preprocess v4.6.9 from c:\Users\**redacted**\.vscode\extensions\svelte.svelte-vscode-104.9.1\node_modules\svelte-preprocess
No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
Using svelte-preprocess v4.6.9 from c:\Users\**redacted**\.vscode\extensions\svelte.svelte-vscode-104.9.1\node_modules\svelte-preprocess
Using Svelte v3.24.0 from c:\**redacted project folder**\node_modules\svelte\compiler
Using Svelte v3.24.0 from c:\**redacted project folder**\node_modules\svelte\compiler
Using Svelte v3.24.0 from c:\**redacted project folder**\node_modules\svelte\compiler
Using Svelte v3.24.0 from c:\**redacted project folder**\node_modules\svelte\compiler
Using Svelte v3.24.0 from c:\**redacted project folder**\node_modules\svelte\compiler
Using Svelte v3.24.0 from c:\**redacted project folder**\node_modules\svelte\compiler
Using Svelte v3.24.0 from c:\**redacted project folder**\node_modules\svelte\compiler
Using Svelte v3.24.0 from c:\**redacted project folder**\node_modules\svelte\compiler
Using Svelte v3.24.0 from c:\**redacted project folder**\node_modules\svelte\compiler
Using Svelte v3.24.0 from c:\**redacted project folder**\node_modules\svelte\compiler
Using Svelte v3.24.0 from c:\**redacted project folder**\node_modules\svelte\compiler
Using Svelte v3.24.0 from c:\**redacted project folder**\node_modules\svelte\compiler
SnapshotManager File Statistics:
Project files: 0
Svelte files: 20
From node_modules: 944
Total: 964
Using Svelte v3.24.0 from c:\**redacted project folder**\node_modules\svelte\compiler
Using Svelte v3.24.0 from c:\**redacted project folder**\node_modules\svelte\compiler
Using Svelte v3.24.0 from c:\**redacted project folder**\node_modules\svelte\compiler
Using Svelte v3.24.0 from c:\**redacted project folder**\node_modules\svelte\compiler
Using Svelte v3.24.0 from c:\**redacted project folder**\node_modules\svelte\compiler
Using Svelte v3.24.0 from c:\**redacted project folder**\node_modules\svelte\compiler

Also, here is the VScode ram usage:
image

@rchl
Copy link
Member

rchl commented Apr 20, 2021

How do you get it to discover all those files? For me, it starts with 0 files in all categories and doesn't increase. I've created a simple project with https://github.com/sveltejs/template.

My suspicion is that this is related to file watching which LSP/ST doesn't support so it's falling back to an internal one. But it's just a wild guess at this point.

@BanjoCam
Copy link
Author

BanjoCam commented Apr 20, 2021

Honestly, I have no idea. I am using largely on a fresh install of ST/Vscode and did not additional configuration - this is what the plugins are doing on my existing projects.

I actually did try on a simple default svelte project. It works more as expected (ie - is usable and the RAM is not out of control.) It always starts finding 0 packages but a bit later will update with more. In this case it said zero, but after I ran the "format file" command, it spits out a new log with more file statistics.

LSP-svelte: SnapshotManager File Statistics:
LSP-svelte: Project files: 0
LSP-svelte: Svelte files: 0
LSP-svelte: From node_modules: 0
LSP-svelte: Total: 0
LSP-svelte: Using Svelte v3.37.0 from c:\Users\**redacted**\Documents\Projects\testing-sublime\node_modules\svelte\compiler
LSP-svelte: Using Svelte v3.37.0 from c:\Users\**redacted**\Documents\Projects\testing-sublime\node_modules\svelte\compiler
LSP-svelte: Using Prettier v2.2.1 from C:\Users\**redacted**\AppData\Local\Sublime Text 3\Package Storage\LSP-svelte\14.16.0\server\node_modules\prettier
LSP-svelte: Using Svelte v3.37.0 from c:\Users\**redacted**\Documents\Projects\testing-sublime\node_modules\svelte\compiler
LSP-svelte: SnapshotManager File Statistics:
LSP-svelte: Project files: 0
LSP-svelte: Svelte files: 1
LSP-svelte: From node_modules: 741
LSP-svelte: Total: 745

@BanjoCam
Copy link
Author

Hi again,

So I went into the SnapshotManager.js file found in both the Sublime and VSCode plugins. I added a "output list of files" function to the logger so I could compare what is getting included in the watcher scan. Sublime seems to be including EVERYTHING in node_modules. VSCode seems to (just eyeballing it) be limiting to files in the src folder, @types folder, and then ONLY including node_modules folders with the word "svelte" in them. I'd imagine this filter would be the main reason why the sublime file list is out of control. I have been trying to find in the vscode plugin where this filter would actually be defined, with no luck. But I would imagine that is the difference maker here.

@rchl
Copy link
Member

rchl commented Apr 20, 2021

The client only tells the server which root folders (typically just one) are in the project (through the initialize message) and then notifying about each file that is opened. It doesn't really send any paths or filters besides that, as far as I can think of.

@rchl
Copy link
Member

rchl commented Apr 20, 2021

You can enable server communication logs on both ST and vscode and compare what is being sent.

@rwols
Copy link
Member

rwols commented Apr 20, 2021

Perhaps it’s some server setting that is different?

@ghost
Copy link

ghost commented Apr 20, 2021

Perhaps it’s some server setting that is different?

I believe this one is different

dontFilterIncompleteCompletions: true

https://github.com/sveltejs/language-tools/blob/master/packages/svelte-vscode/src/extension.ts#L102

Also prettier and emmet configs are missing

I will only take a look on the weekends

@BanjoCam
Copy link
Author

Thanks for all the help.

You can enable server communication logs on both ST and vscode and compare what is being sent.

I figured out how to do this in VSCode (pasted below) but I don't see how to do it in ST?

Also, I added the following lines to SnapshotManager.js (set function, line ~60) in the svelte-language-server node_modules folder, just to expierment:

      if (fileName.includes('svelte') || fileName.includes('src')) {
            return this.documents.set(fileName, snapshot);
        }

That little tweak alone keeps the RAM usage under 1GB and makes the plugin quasi-usable... seems like kind of a crummy hack?

VSCode server log:

"settings": {
        "svelte": {
            "language-server": {
                "runtime": "",
                "ls-path": "",
                "port": -1
            },
            "trace": {
                "server": "verbose"
            },
            "plugin": {
                "typescript": {
                    "enable": true,
                    "diagnostics": {
                        "enable": true
                    },
                    "hover": {
                        "enable": true
                    },
                    "documentSymbols": {
                        "enable": true
                    },
                    "completions": {
                        "enable": true
                    },
                    "findReferences": {
                        "enable": true
                    },
                    "definitions": {
                        "enable": true
                    },
                    "codeActions": {
                        "enable": true
                    },
                    "selectionRange": {
                        "enable": true
                    },
                    "signatureHelp": {
                        "enable": true
                    },
                    "rename": {
                        "enable": true
                    },
                    "semanticTokens": {
                        "enable": true
                    }
                },
                "css": {
                    "enable": true,
                    "globals": "",
                    "diagnostics": {
                        "enable": true
                    },
                    "hover": {
                        "enable": true
                    },
                    "completions": {
                        "enable": true,
                        "emmet": true
                    },
                    "documentColors": {
                        "enable": true
                    },
                    "colorPresentations": {
                        "enable": true
                    },
                    "documentSymbols": {
                        "enable": true
                    },
                    "selectionRange": {
                        "enable": true
                    }
                },
                "html": {
                    "enable": true,
                    "hover": {
                        "enable": true
                    },
                    "completions": {
                        "enable": true,
                        "emmet": true
                    },
                    "tagComplete": {
                        "enable": true
                    },
                    "documentSymbols": {
                        "enable": true
                    },
                    "linkedEditing": {
                        "enable": true
                    },
                    "renameTags": {
                        "enable": true
                    }
                },
                "svelte": {
                    "enable": true,
                    "diagnostics": {
                        "enable": true
                    },
                    "compilerWarnings": {},
                    "format": {
                        "enable": true,
                        "config": {
                            "svelteSortOrder": "options-scripts-markup-styles",
                            "svelteStrictMode": false,
                            "svelteAllowShorthand": true,
                            "svelteBracketNewLine": true,
                            "svelteIndentScriptAndStyle": true,
                            "printWidth": 80,
                            "singleQuote": false
                        }
                    },
                    "completions": {
                        "enable": true
                    },
                    "hover": {
                        "enable": true
                    },
                    "codeActions": {
                        "enable": true
                    },
                    "selectionRange": {
                        "enable": true
                    },
                    "rename": {
                        "enable": true
                    }
                }
            }
        },
        "javascript": {
            "referencesCodeLens": {
                "enabled": false,
                "showOnAllFunctions": false
            },
            "suggest": {
                "completeFunctionCalls": false,
                "includeAutomaticOptionalChainCompletions": true,
                "names": true,
                "paths": true,
                "autoImports": true,
                "completeJSDocs": true,
                "jsdoc": {
                    "generateReturns": true
                },
                "enabled": true
            },
            "validate": {
                "enable": true
            },
            "format": {
                "enable": true,
                "insertSpaceAfterCommaDelimiter": true,
                "insertSpaceAfterConstructor": false,
                "insertSpaceAfterSemicolonInForStatements": true,
                "insertSpaceBeforeAndAfterBinaryOperators": true,
                "insertSpaceAfterKeywordsInControlFlowStatements": true,
                "insertSpaceAfterFunctionKeywordForAnonymousFunctions": true,
                "insertSpaceBeforeFunctionParenthesis": false,
                "insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
                "insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
                "insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true,
                "insertSpaceAfterOpeningAndBeforeClosingEmptyBraces": true,
                "insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false,
                "insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false,
                "placeOpenBraceOnNewLineForFunctions": false,
                "placeOpenBraceOnNewLineForControlBlocks": false,
                "semicolons": "ignore"
            },
            "implicitProjectConfig": {
                "checkJs": false,
                "experimentalDecorators": false
            },
            "suggestionActions": {
                "enabled": true
            },
            "preferences": {
                "quoteStyle": "auto",
                "importModuleSpecifier": "shortest",
                "importModuleSpecifierEnding": "auto",
                "renameShorthandProperties": true,
                "useAliasesForRenames": true
            },
            "updateImportsOnFileMove": {
                "enabled": "prompt"
            },
            "autoClosingTags": true
        },
        "typescript": {
            "tsdk": null,
            "disableAutomaticTypeAcquisition": false,
            "enablePromptUseWorkspaceTsdk": false,
            "npm": null,
            "check": {
                "npmIsInstalled": true
            },
            "referencesCodeLens": {
                "enabled": false,
                "showOnAllFunctions": false
            },
            "implementationsCodeLens": {
                "enabled": false
            },
            "tsserver": {
                "enableTracing": false,
                "log": "off",
                "pluginPaths": [],
                "trace": "off",
                "useSeparateSyntaxServer": true,
                "maxTsServerMemory": 3072,
                "experimental": {
                    "enableProjectDiagnostics": false
                },
                "watchOptions": {}
            },
            "suggest": {
                "completeFunctionCalls": false,
                "includeAutomaticOptionalChainCompletions": true,
                "paths": true,
                "autoImports": true,
                "completeJSDocs": true,
                "jsdoc": {
                    "generateReturns": true
                },
                "enabled": true
            },
            "reportStyleChecksAsWarnings": true,
            "validate": {
                "enable": true
            },
            "format": {
                "enable": true,
                "insertSpaceAfterCommaDelimiter": true,
                "insertSpaceAfterConstructor": false,
                "insertSpaceAfterSemicolonInForStatements": true,
                "insertSpaceBeforeAndAfterBinaryOperators": true,
                "insertSpaceAfterKeywordsInControlFlowStatements": true,
                "insertSpaceAfterFunctionKeywordForAnonymousFunctions": true,
                "insertSpaceBeforeFunctionParenthesis": false,
                "insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
                "insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
                "insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true,
                "insertSpaceAfterOpeningAndBeforeClosingEmptyBraces": true,
                "insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false,
                "insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false,
                "insertSpaceAfterTypeAssertion": false,
                "placeOpenBraceOnNewLineForFunctions": false,
                "placeOpenBraceOnNewLineForControlBlocks": false,
                "semicolons": "ignore"
            },
            "tsc": {
                "autoDetect": "on"
            },
            "locale": null,
            "suggestionActions": {
                "enabled": true
            },
            "preferences": {
                "quoteStyle": "auto",
                "importModuleSpecifier": "shortest",
                "importModuleSpecifierEnding": "auto",
                "includePackageJsonAutoImports": "auto",
                "renameShorthandProperties": true,
                "useAliasesForRenames": true
            },
            "updateImportsOnFileMove": {
                "enabled": "prompt"
            },
            "autoClosingTags": true,
            "surveys": {
                "enabled": true
            },
            "workspaceSymbols": {
                "scope": "allOpenProjects"
            }
        }
    }

@rchl
Copy link
Member

rchl commented Apr 20, 2021

Your log from vscode is not very complete. It's missing all the message exchange. Seeing the request and response for the initialize request could be especially useful.

In ST4 you enable logging with "log_server": ["panel"], in LSP settings.
And in ST3 with:

"log_debug": true,
"log_server": true,
"log_payloads": true,

@rchl
Copy link
Member

rchl commented Apr 20, 2021

My suspicion is that this is related to file watching which LSP/ST doesn't support so it's falling back to an internal one. But it's just a wild guess at this point.

It could be that. See sveltejs/language-tools#841 . It creates a file watcher without excluding node_modules.

In VSCode it creates a watcher using VSCode's API (here https://github.com/sveltejs/language-tools/blob/de1699fd0aa6e95dded33ad9ac7a8e4c25ea9083/packages/svelte-vscode/src/extension.ts#L92) which I think ignores changes to gitignored files and directories like node_modules internally.

If that's that then a way to reproduce could be to rm -rf node_modules and then re-install dependencies again.

cc @jasonlyu123

@BanjoCam
Copy link
Author

The log I included there was only when I changed the settings to "verbose" in vscode but I did include a log earlier #44 (comment) that had the initialize code for ST and VScode. Does that look right?

I am playing around on my Mac at home, I had cloned my repo and actually forgot to do an npm install when I was testing yesterday. It loaded 85 files before I did the install and was working great. After the install it simply crashed and showed this in the log:

LSP-svelte: Initialize language server at  file:///Users/cam/development/toci_frontend
LSP-svelte: Initialize new ts service at
LSP-svelte: Trying to load configs for
LSP-svelte: No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
LSP-svelte: Using svelte-preprocess v4.6.9 from /Users/cam/Library/Application Support/Sublime Text/Package Storage/LSP-svelte/15.14.0/server/node_modules/svelte-preprocess
LSP-svelte: SnapshotManager File Statistics:
LSP-svelte: Project files: 0
LSP-svelte: Svelte files: 0
LSP-svelte: From node_modules: 0
LSP-svelte: Total: 0
LSP-svelte: No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
LSP-svelte: Using svelte-preprocess v4.6.9 from /Users/cam/Library/Application Support/Sublime Text/Package Storage/LSP-svelte/15.14.0/server/node_modules/svelte-preprocess
LSP-svelte: Using Svelte v3.16.7 from /Users/cam/development/toci_frontend/node_modules/svelte/compiler
LSP-svelte: No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
LSP-svelte: Using svelte-preprocess v4.6.9 from /Users/cam/Library/Application Support/Sublime Text/Package Storage/LSP-svelte/15.14.0/server/node_modules/svelte-preprocess
LSP-svelte: No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
LSP-svelte: Using svelte-preprocess v4.6.9 from /Users/cam/Library/Application Support/Sublime Text/Package Storage/LSP-svelte/15.14.0/server/node_modules/svelte-preprocess
LSP-svelte: Using Svelte v3.16.7 from /Users/cam/development/toci_frontend/node_modules/svelte/compiler
LSP-svelte: Using Svelte v3.16.7 from /Users/cam/development/toci_frontend/node_modules/svelte/compiler
LSP-svelte: Using Svelte v3.16.7 from /Users/cam/development/toci_frontend/node_modules/svelte/compiler
LSP-svelte: No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
LSP-svelte: Using svelte-preprocess v4.6.9 from /Users/cam/Library/Application Support/Sublime Text/Package Storage/LSP-svelte/15.14.0/server/node_modules/svelte-preprocess
LSP-svelte: 
LSP-svelte: <--- Last few GCs --->
LSP-svelte: 
LSP-svelte: [48339:0x1046d9000]    73922 ms: Mark-sweep (reduce) 2045.5 (2083.3) -> 2045.3 (2083.3) MB, 2142.4 / 0.0 ms  (average mu = 0.059, current mu = 0.001) allocation failure GC in old space requested
LSP-svelte: [48339:0x1046d9000]    76247 ms: Mark-sweep (reduce) 2045.3 (2083.3) -> 2045.3 (2083.3) MB, 2325.6 / 0.0 ms  (average mu = 0.029, current mu = 0.000) allocation failure GC in old space requested
LSP-svelte: 
LSP-svelte: 
LSP-svelte: <--- JS stacktrace --->
LSP-svelte: 
LSP-svelte: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
LSP-svelte:  1: 0x1000affe8 node::Abort() [/usr/local/bin/node]
LSP-svelte:  2: 0x1000b015e node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
LSP-svelte:  3: 0x1001eff51 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
LSP-svelte:  4: 0x1001efefb v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
LSP-svelte:  5: 0x1003348d7 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
LSP-svelte:  6: 0x100335be4 v8::internal::Heap::MarkCompactPrologue() [/usr/local/bin/node]
LSP-svelte:  7: 0x100333441 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/bin/node]
LSP-svelte:  8: 0x1003319cb v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
LSP-svelte:  9: 0x10033a79a v8::internal::Heap::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
LSP-svelte: 10: 0x10033a7f2 v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
LSP-svelte: 11: 0x10031236d v8::internal::FactoryBase<v8::internal::Factory>::AllocateRawArray(int, v8::internal::AllocationType) [/usr/local/bin/node]
LSP-svelte: 12: 0x100312144 v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArrayWithFiller(v8::internal::Handle<v8::internal::Map>, int, v8::internal::Handle<v8::internal::Oddball>, v8::internal::AllocationType) [/usr/local/bin/node]
LSP-svelte: 13: 0x1004e1681 v8::internal::OrderedHashTable<v8::internal::OrderedHashMap, 2>::Allocate(v8::internal::Isolate*, int, v8::internal::AllocationType) [/usr/local/bin/node]
LSP-svelte: 14: 0x1004e361f v8::internal::OrderedHashTable<v8::internal::OrderedHashMap, 2>::Rehash(v8::internal::Isolate*, v8::internal::Handle<v8::internal::OrderedHashMap>, int) [/usr/local/bin/node]
LSP-svelte: 15: 0x100586648 v8::internal::Runtime_MapGrow(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]
LSP-svelte: 16: 0x10081e6b9 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/usr/local/bin/node]
LSP-svelte: 17: 0x1007f8b31 Builtins_MapPrototypeSet [/usr/local/bin/node]

On vscode:

Initialize language server at  file:///Users/cam/development/toci_frontend
No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
Using svelte-preprocess v4.6.9 from /Users/cam/.vscode/extensions/svelte.svelte-vscode-104.9.1/node_modules/svelte-preprocess
Initialize new ts service at  
Trying to load configs for 
No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
Using svelte-preprocess v4.6.9 from /Users/cam/.vscode/extensions/svelte.svelte-vscode-104.9.1/node_modules/svelte-preprocess
SnapshotManager File Statistics:
Project files: 0
Svelte files: 0
From node_modules: 0
Total: 0
Using Svelte v3.16.7 from /Users/cam/development/toci_frontend/node_modules/svelte/compiler
No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
Using svelte-preprocess v4.6.9 from /Users/cam/.vscode/extensions/svelte.svelte-vscode-104.9.1/node_modules/svelte-preprocess
No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
Using svelte-preprocess v4.6.9 from /Users/cam/.vscode/extensions/svelte.svelte-vscode-104.9.1/node_modules/svelte-preprocess
Using Svelte v3.16.7 from /Users/cam/development/toci_frontend/node_modules/svelte/compiler
Using Svelte v3.16.7 from /Users/cam/development/toci_frontend/node_modules/svelte/compiler
Using Svelte v3.16.7 from /Users/cam/development/toci_frontend/node_modules/svelte/compiler
Using Svelte v3.16.7 from /Users/cam/development/toci_frontend/node_modules/svelte/compiler
Using Svelte v3.16.7 from /Users/cam/development/toci_frontend/node_modules/svelte/compiler
Using Svelte v3.16.7 from /Users/cam/development/toci_frontend/node_modules/svelte/compiler
Using Svelte v3.16.7 from /Users/cam/development/toci_frontend/node_modules/svelte/compiler
Using Svelte v3.16.7 from /Users/cam/development/toci_frontend/node_modules/svelte/compiler
Using Svelte v3.16.7 from /Users/cam/development/toci_frontend/node_modules/svelte/compiler
SnapshotManager File Statistics:
Project files: 0
Svelte files: 6
From node_modules: 147
Total: 153
Using Svelte v3.16.7 from /Users/cam/development/toci_frontend/node_modules/svelte/compiler
Using Svelte v3.16.7 from /Users/cam/development/toci_frontend/node_modules/svelte/compiler
Using Prettier v1.19.1 from /Users/cam/development/toci_frontend/node_modules/prettier

So, exactly the same issues (file counts are a bit different likely because this is a different project, but very similar in structure.)

@jasonlyu123
Copy link

jasonlyu123 commented Apr 21, 2021

I also suspect it's related to file watching. We just have a PR sveltejs/language-tools#950 to exclude node_modules from the fallback watcher. From his investigation, there are likely other language services initialized to target a module in the node_module folder. Maybe that would help.
Can you provide a reproducible case or step so I can verify if that fixes the problem? From my understanding, it should only happen when npm install but you seem to be able to consistently reproduce it. Maybe there's another reason file watcher detects changes.

@BanjoCam
Copy link
Author

The codebases I'm currently working on are not super shareable. If I get some time tomorrow I'll try to make a dummy codebase that can re-create the issue and could be used for testing.

FYI I just did the same experiment (git clone repo, npm install, then open Sublime and point to it) on my beefier linux box, and am getting the same issues (7000+ files scanned, about 2.5GB ram used).

Thanks again!

@rchl
Copy link
Member

rchl commented Apr 21, 2021

@BanjoCam if that suspicion is correct then disabling the following code should result in the problem going away
https://github.com/sveltejs/language-tools/blob/de1699fd0aa6e95dded33ad9ac7a8e4c25ea9083/packages/language-server/src/server.ts#L102-L106

@BanjoCam
Copy link
Author

BanjoCam commented Apr 21, 2021

@BanjoCam if that suspicion is correct then disabling the following code should result in the problem going away
https://github.com/sveltejs/language-tools/blob/de1699fd0aa6e95dded33ad9ac7a8e4c25ea9083/packages/language-server/src/server.ts#L102-L106

Wow! I don't know how to recompile the server, but I went into the compiled plugin directory and opened the compiled server.js file. I found what appeared to be the compiled version of this ts code (lines 57-61)

        if (!((_d = evt.capabilities.workspace) === null || _d === void 0 ? void 0 : _d.didChangeWatchedFiles)) {
            const workspacePaths = workspaceUris.map(utils_1.urlToPath).filter(utils_1.isNotNullOrUndefined);
            watcher = new FallbackWatcher_1.FallbackWatcher('**/*.{ts,js}', workspacePaths);
            watcher.onDidChangeWatchedFiles(onDidChangeWatchedFiles);
        }

and commented it out. Restarted sublime - node is sitting around 239mb ram now, the plugin is performant similar to the VSCode one. After the initial "files: 0" that always appears in the LSP logs, I now see

LSP-svelte: SnapshotManager File Statistics:
LSP-svelte: Project files: 0
LSP-svelte: Svelte files: 18
LSP-svelte: From node_modules: 873
LSP-svelte: Total: 892

which again is very similar to VSCode. It stops updating after this and doesn't grow into the thousands as before.

THANK YOU!

EDIT: tried the same fix on my mac and also worked 👍

@ghost
Copy link

ghost commented Apr 23, 2021

@BanjoCam, I've just pushed v1.1.15. It will be available soon on Package Control. Please, check it when you have some time. I hope the issue is fixed :)

@BanjoCam
Copy link
Author

Yes - it works, and it's glorious!

@ghost ghost closed this as completed Apr 26, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants