Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Improves performance when analyzing on save. #12

Merged
merged 4 commits into from
Jul 21, 2017
Merged

Improves performance when analyzing on save. #12

merged 4 commits into from
Jul 21, 2017

Conversation

faustinoaq
Copy link
Member

@faustinoaq faustinoaq commented Jul 10, 2017

Hi @kofno I did some improves.

  • Verify that document text is different before analyze.
  • Ensure to execute Garbage Collector. (free some MB)
  • Avoid to check files shards and crystal lib.

@@ -5,12 +5,22 @@ require "./publish_diagnostic"

module Scry
struct Analyzer
@@source = [] of String
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been out of the Scry codebase for a while, but I'm a bit concerned about this being set as a class var. Doesn't this make it impossible to check a project with multiple files against a single running server instance?

Copy link
Member Author

@faustinoaq faustinoaq Jul 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In VSCode, every workspace launch a new instance of scry, in NVIM too. I don't know in Atom, however if the code inside text_document.text changes, then the source file is updated.

My goals with this variable is to check that source is different when document is saved, because the actual behavior is checking the file too much, spending memory and CPU time even when code is the same.

It's a class variable because a new instance of Analyzer is created in a new message, and I didn't have other way to handle this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can leave this for now, but this seems like a likely place for a race condition. It may be time to consider re-architecting the Analyzer.

if @@source != @text_document.text
@@source = @text_document.text
@@source.map do |text|
unless @text_document.filename.starts_with?("/usr/lib") ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a global shard home directory? Is there an env var we could use instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I can use, ENV["CRYSTAL_PATH"]
Let me fix that, I will do on weekend.

@@ -39,6 +39,10 @@ module Scry
end
ResponseMessage.new(@text_document.id, locations)
end
rescue ex
nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we at least log that an exception happened? What kind of exceptions are we expecting here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes something like, Log.logger.error("A error was found while searching definitions\n#{ex}")

@faustinoaq
Copy link
Member Author

@kofno Thanks you for review my code 😅

I will improve this PR on weekend.

The aims of this PR is to reduce scry resources, because currently scry analyzer take up to 500 Mb with a simple file.

Without analyzer scry uses only 10Mb in my computer to do formatting, syntax checking and goto defitiniton.

I know that isn't a scry problem but a crystal problem, but at least we can do something for now.

Cheers

@faustinoaq
Copy link
Member Author

faustinoaq commented Jul 12, 2017 via email

@kofno
Copy link
Contributor

kofno commented Jul 14, 2017

I want to read of the code for some of the the other language servers, just to get some ideas before we get too deep into refactoring. I'd also like to read some general Crystal and Go server code to get a good feel for using channels again. I worked through some examples before, but I need a refresher I think.

@faustinoaq
Copy link
Member Author

faustinoaq commented Jul 19, 2017

Hi @kofno 😄

I removed @@souce class variable, and now it uses CRYSTAL_PATH to avoid check files inside crystal lib.
Also added logger when implementations search fail.

@faustinoaq
Copy link
Member Author

faustinoaq commented Jul 21, 2017

@kofno can you check this, please 😅, I want to delete my fork because I made some mistakes 😅 while I was merging in other branches, so I want to create a new clean fork from this repo.

@kofno kofno merged commit 5618746 into crystal-lang-tools:master Jul 21, 2017
@kofno
Copy link
Contributor

kofno commented Jul 21, 2017

Done! Thanks again!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants