nathankot/company-sourcekit

Serious perfomance problem

galeo opened this issue · 11 comments

galeo commented

Sorry,

but how could I achieve the code completion speed the gif demo showed? It is so slow as to be pretty much unusable.

The sourcekit-output-buffer has been kept on filling with too much JSON output (tens of thousands of lines), the completion work is endured endless waiting.

What version of XCode and sourcekittendaemon are you using?

The endless output is a known issue and usually only occurs in the case when there is no optimal completion anyway, if you keep typing the sourcekitten query will be replaced with a new one. Xcode also deals this kind of endless output but I believe it parses the results in a streaming fashion - something that's needed in company-sourcekit but hasn't been implemented yet, json.el doesn't seem to have any form of streaming support.

That being said, it works fine for me at the speed shown in the demo - try upgrading to the latest versions of XCode and sourcekittendaemon. If you find an issue, feel free to make a pull request.

galeo commented

I use Xcode 7.3 and sourcekittendaemon 0.11.0, both of them are the latest version.

Thanks.

Hey @galeo please try 0.1.6 and see how it goes, see #17 where this issue was discussed.
Feel free to re-open if you're still running into problems :)

galeo commented

Hi, @nathankot. I've just tried 0.1.6, the 400K+ problem didn't occur again. Thank you for your work. However, the completion expanded with a small error.

The candidates showed:
pic-1
After choosing the selection:
pic-2
See the parens?

Another case,
pic-3
After completing:
pic-4

It seems that the completion work did't handle the context characters.

Hey @galeo this is what I see:

screen shot 2016-05-07 at 11 33 45 pm
screen shot 2016-05-07 at 11 34 59 pm

This is the output of my xcodebuild -version:

Xcode 7.3.1
Build version 7D1014

It's weird how you're getting (...) responses from the daemon, while I'm getting ....
Can you turn on company-sourcekit-verbose and see if the offset that's being sent comes 1 character after the (?

galeo commented

Hi, @nathankot. I also use Xcode 7.3.1(7D1014).

Here is the log:
pic-5

It works fine just when I delete some comments:
pic-6

@galeo very interesting find! I can reproduce this behavior as well, doing some more investigation atm to see if I can get to the bottom of this.

I've tracked it down to the copyright symbol © if you remove that individual symbol completion will work as advertised, I'm hoping this is a discrepancy in how emacs vs xcode calculates the offset of this character

Here are my findings using sourcekitten:

Completion without the copyright symbol, offset is at: CGRect(|):

$ sourcekitten complete --text '# ; import AVFoundation; CGRect()' --offset 32 | head
[{
  "descriptionKey" : "(origin: CGPoint, size: CGSize)",
  "associatedUSRs" : "s:FVSC6CGRectcFT6originVSC7CGPoint4sizeVSC6CGSize_S_",
  "kind" : "source.lang.swift.decl.function.constructor",
  "sourcetext" : "origin: <#T##CGPoint#>, size: <#T##CGSize#>",
  "context" : "source.codecompletion.context.thisclass",
  "typeName" : "CGRect",
  "moduleName" : "CoreGraphics",
  "name" : "origin:size:"
}, {

Completion with the copyright symbol, offset is at CGRect(|):

$ sourcekitten complete --text '# ©; import AVFoundation; CGRect()' --offset 33 | head
[{
  "descriptionKey" : "()",
  "associatedUSRs" : "s:FVSC6CGRectcFT_S_",
  "kind" : "source.lang.swift.decl.function.constructor",
  "sourcetext" : "()",
  "context" : "source.codecompletion.context.thisclass",
  "typeName" : "CGRect",
  "moduleName" : "CoreGraphics",
  "name" : "()"
}, {

Completion with the copyright symbol, offset is (seemingly) incorrect at CGRect()|:

$ sourcekitten complete --text '# ©; import AVFoundation; CGRect()' --offset 34 | head
[{
  "descriptionKey" : "(origin: CGPoint, size: CGSize)",
  "associatedUSRs" : "s:FVSC6CGRectcFT6originVSC7CGPoint4sizeVSC6CGSize_S_",
  "kind" : "source.lang.swift.decl.function.constructor",
  "sourcetext" : "origin: <#T##CGPoint#>, size: <#T##CGSize#>",
  "context" : "source.codecompletion.context.thisclass",
  "typeName" : "CGRect",
  "moduleName" : "CoreGraphics",
  "name" : "origin:size:"
}, {

It looks like xcode isn't considering the © character at all, I'm going to make a new issue on terhechte/SouceKittenDaemon with these findings as it'd be nice to fix this at a level above the editor integration.

@galeo this has been fixed in the latest release :)

galeo commented

👍 Thanks a lot!