Fork me on GitHub
#lsp
<
2022-09-24
>
pez09:09:54

Is it by intention that def and defn are tokenized as functions with the nightly build?

pez09:09:05

Wait. Re-downloading nightly it started to work as before again. Never mind me!

ericdallo12:09:48

Yeah, I noticed that too, some build broke that not sure where or what, but was probably relate switch some kondo bump

ericdallo13:09:13

Anyway, seems fixed on nightly as you mentioned indeed

pez13:09:31

Yeah, I'm happy. 😃 Will remember to restart clojure-lsp to check if what I see on nightly is latest nightly.

ericdallo14:09:26

clojure-lsp For anyone with performance issues after latest release update, please try the https://clojurians.slack.com/archives/C032YH7P0R2/p1664027949770639(2022.09.24-13.47.40-nightly), it should be fixed 🎉 We changed how lsp4j handle multiple requests/responses and we should have the same behavior as previous release, please let us know if any issues! Kudos to @jacob.maine for the huge deep dive and fix gratitude We should do a release soon with this fix and other bugfixes/new features 🤞

🎉 1
borkdude14:09:39

@ericdallo I'm super stoked about this fix. Thanks @jacob.maine - I'll be trying it out!

🚀 1
borkdude14:09:14

sorry for not using a thread :)

😛 1
clojure-spin 1
2
borkdude14:09:10

I wish I intended that pun!

😂 2
ericdallo14:09:38

It's ok, I knew you were excited :)

borkdude14:09:08

I've tested it and it still isn't nearly as responsive as the lsp4j one

borkdude14:09:43

in squint compiler.cljc I'm typing x-es on line 144 here:

(str sym-ns "_" xxxxx(munged-name sn))

ericdallo14:09:58

Hum, I was having the same slowness as you but now it's gone, could you confirm your clojure-lsp --version ?

borkdude14:09:03

when I type x-es and then quickly backspace and then x-es again, it blocks my buffer

borkdude14:09:17

$ clojure-lsp --version
clojure-lsp 2022.09.24-13.47.55-nightly
clj-kondo 2022.09.09-SNAPSHOT

ericdallo14:09:59

Just tried your code and can't repro the slowness, is your editor freezing or only diagnostics are taking some time to show?

borkdude14:09:02

Let me try to make a gif, like last time

ericdallo14:09:53

Hum, it's really smooth to me, I can't make emacs block no matter how much x or how fast or slow I type :thinking_face:

ericdallo14:09:52

@jacob.maine do you think the parallelism level would make that big difference? as your was 3 and for mine was 7 IIRC, maybe borkdude has 3 as well

borkdude14:09:08

You have to type a few x-es and then stop for 1 second and then type again, then you'll notice the micro-freeze

jacob.maine14:09:18

yes, it definitely makes a difference

ericdallo14:09:19

yeah, for me it's perfect :/ @U04V15CAJ could you confirm that emacs is using that clojure-lsp, checking the version on lsp-clojure-server-info

borkdude14:09:55

yes, I checked it, it's using the nightly and when I swap it back with the one from June it behaves smoothly

😔 1
ericdallo14:09:49

@jacob.maine since you have a low parallelism level, could you try borkdude's repro?

ericdallo14:09:48

@U04V15CAJ I suppose you are using M1, using aarch64 binary right? maybe just give a try on the macos amd64 one or build clojure-lsp from master, since aarch64 uses a different CI, maybe could have a CI bug or something and it's using other version

borkdude14:09:21

it is reporting the correct version, right? yes, I can try the amd64 one

ericdallo14:09:17

yeah, it's just that I changed how that works in the last week and made me think that we might have a bug on the Cirrus release, probably it's not a issue, but I think worth the try

borkdude14:09:40

Same issue with amd64. The trick is to type a few x-es, then wait a little bit and then type again.

😔 1
jacob.maine14:09:50

I’m going to be offline for the next several hours. I can reproduce small lags if I type, but only if I type very slowly. @U04V15CAJ, have you changed your lsp-idle-delay away from the default of 0.5? I’m not sure it’s possible, but I’d love to have your server logs @U04V15CAJ right around the moment that the freeze happens. What I really need is the logs with tracing turned on, which means uncommenting the tracing lines in clojure_lsp/server.clj, and making a new build. If that’s too much hassle, I’ll plan to analyze my logs as soon as I can

ericdallo14:09:00

You do have a lsp-idel-delay of 0.5, so probably not related (I have mine of 0.2)

borkdude14:09:04

Maybe you can make a configuration option so I can set tracing on in there?

borkdude14:09:09

and then download a nightly

ericdallo14:09:15

yeah, I was thinking about that to do soon

ericdallo14:09:42

the issue is that at that time we don't have access to settings :/ as we don't even know the project-root

jacob.maine14:09:48

Sorry, have to sign off. Will check in later

👍 1
ericdallo14:09:09

I'll think about something else to make the trace enable easier, meanwhile, let us know if you can do the change manually @U04V15CAJ otherwise we wait for @jacob.maine logs

jacob.maine14:09:20

@ericdallo there’s mechanics for this in LSP, something like setTraceLevel. when starting the server we’ll always pass a trace-ch We need to take that level and pass it through to lsp4clj. Then lsp4clj needs to respect a level like :off.

jacob.maine14:09:44

Sorry, that’s a little incoherent. We can talk about it later

👍 1
ericdallo14:09:46

Yeah, I was thinking about a variable which makes client send a setting at start

borkdude14:09:00

I can wait for this change

borkdude14:09:31

or maybe you can make a branch so I can download the changed binary from cirrus

ericdallo14:09:06

Cirrus just build the binary on master

borkdude14:09:18

ok, I'll try a local build

borkdude14:09:42

trying:

bb native-cli

borkdude14:09:07

I have the local build now with trace on

borkdude14:09:46

here is a log

👍 1
borkdude14:09:09

could it be this?

2022-09-24T14:53:55.751Z  DEBUG [clojure-lsp.server:40] - [Trace - 2022-09-24T14:53:55.751Z] Sending response 'textDocument/documentHighlight - (33)'. Request took 592ms.
takes a long time it seems?

ericdallo14:09:27

that buffer is not small so it's expected that I think, I the issue probably won't be a specific request but the group of multiples during a small window which makes a issue hard to debug

borkdude14:09:42

also this one:

2022-09-24T14:53:55.751Z  DEBUG [clojure-lsp.server:40] - [Trace - 2022-09-24T14:53:55.750Z] Sending response 'textDocument/codeLens - (35)'. Request took 588ms.

borkdude14:09:01

and this one:

2022-09-24T14:53:55.752Z  DEBUG [clojure-lsp.server:40] - [Trace - 2022-09-24T14:53:55.751Z] Sending response 'textDocument/documentSymbol - (34)'. Request took 592ms.

borkdude14:09:28

2022-09-24T14:53:55.783Z  DEBUG [clojure-lsp.server:40] - [Trace - 2022-09-24T14:53:55.782Z] Sending response 'textDocument/codeAction - (32)'. Request took 623ms. Request failed: The request {:id 32, :method "textDocument/codeAction"} has been cancelled. (-32800).
Error data: {
  "id" : 32,
  "method" : "textDocument/codeAction"
}

borkdude14:09:02

I'll be afk now for a bit

ericdallo15:09:58

Latest nightly accepts a --trace , along with latest lsp-mode , you can now (setq lsp-clojure-trace-enable t) and trace should be enabled

jacob.maine19:09:31

Thanks for the traces @U04V15CAJ. Like me, you’re seeing many requests that take longer than expected, because they wait for a long time to get their turn in the pool. I found one reason for this, which is fixed in https://github.com/clojure-lsp/clojure-lsp/pull/1276. @ericdallo if you could review that, @U04V15CAJ can test it. I’m not sure it will really resolve things, but it could help. You’re also seeing way more Received cancellation notification for unmatched request traces than I am. I’m not sure whether that’s a cause, a symptom, or a side-effect. I’ll have to think about whether there’s a clue there.

👀 1
borkdude19:09:58

@jacob.maine Thanks! Note that I reproduced this by typing a few times, then pausing briefly and then typing again, pausing briefly (until I see the status bar updated) then hitting backspace a few times, etc.

ericdallo19:09:28

The PR looks good to me, I tested manually and it's working as good as before to me, I'm ok merging, or we can wait for borkdude testing it

borkdude19:09:52

OK, merge, then I'll download the nightly

👍 2
jacob.maine19:09:49

Here’s a screen recording of my tests. I have KeyCastr turned on, so you can see how the cursor generally keeps up with the keyboard input. I can maybe detect a small delay while deleting, but it’s subtle. I’ve been trying lots of variations, typing at a pace of 2, 3, or 4 characters per second, as fast as I can, and just holding the key down.

👏 1
borkdude19:09:55

And is it different from before your PR?

jacob.maine19:09:18

No, I’m just demonstrating that I’ve been trying to follow your instructions for how to reproduce it, but haven’t been able to

jacob.maine19:09:44

Yes, that’s the right nightly

borkdude19:09:43

Sadly, I can still reproduce the problem. It is subtle, I agree. I cannot repro it by typing steadily the x-es. But I can repro it by this: Type steadily, then wait .5 seconds, not too long, until lsp has almost finished processing, and then start typing steadily again. This is what you're seeing here: https://clojurians.slack.com/archives/CPABC1H61/p1664029519569659?thread_ts=1664028339.428649&amp;cid=CPABC1H61

ericdallo19:09:52

is it exactly as that gif? if not could you record a new one please?

borkdude19:09:08

I can record a new one.

borkdude19:09:15

Note when I backspace, sometimes 4 x-es are removed at once

borkdude19:09:22

after freezing

ericdallo19:09:37

I wonder if Calva behaves the same, we could remove editor issues possibilities here even knowing this used to work better on previous versions

ericdallo19:09:02

even so, pretty weird how your repro is way slower than mine

jacob.maine19:09:18

That’s a good idea @ericdallo… do you get freezes in Calva @U04V15CAJ? (And btw, thanks for helping us test this!)

jacob.maine20:09:51

I guess I should embark on simulating your system as closely as possible @U04V15CAJ. I don’t have the same hardware as you, but I can do the best I can. You sent me your Emacs config. Do you happen to know which versions of Emacs and lsp-mode you have?

ericdallo20:09:54

Check if emacs was compiled with native compile support as well, the output of lsp-doctor would help with that

borkdude20:09:11

I will try Calva. I run Emacs 28.1 (9.0) downloaded from http://emacsforosx.com. My emacs config is here: https://github.com/borkdude/prelude (note, I've checked all my packages into source control as well, as a de facto way of having version control for my packages... I know)

borkdude20:09:27

lsp-doctor:

Checking for Native JSON support: OK
Check emacs supports `read-process-output-max': OK
Check `read-process-output-max' default has been changed from 4k: OK
Byte compiled against Native JSON (recompile lsp-mode if failing when Native JSON available): OK
`gc-cons-threshold' increased?: OK
Using `plist' for deserialized objects? (refer to ): OPTIONAL
Using emacs 28+ with native compilation?: OPTIONAL

borkdude20:09:22

Note that I didn't have the microfreezes on lsp4j with clojure-lsp (but this was clear already)

👍 1
borkdude20:09:32

will try Calva now

borkdude20:09:10

in Calva I can't reproduce this problem

👍 1
ericdallo20:09:03

@jacob.maine Using promesa we are supposed to be handling requests/responses/cancels as the same lsp4j was doing before right? or are we doing something different?

jacob.maine20:09:07

I tried to follow lsp4j pretty closely. I could try stripping out promesa. It adds some wrappers on top of CompletableFuture, so I could drop down to the lower-level CompletableFuture code that lsp4j was using. There are also a few small ways that the new code flow differs from the old flow. Those differences seem minor to me, but I could try matching everything up even more closely. None of that would hurt, but it’s flying blind if I can’t reproduce the minifreezes locally. Maybe if you audited the differences @ericdallo you’d see something I’m not seeing? The message processing code starts https://github.com/eclipse/lsp4j/blob/89b5cd23def0abbd36e020440c26196c4a5ddde9/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/RemoteEndpoint.java#L184, continues https://github.com/eclipse/lsp4j/blob/89b5cd23def0abbd36e020440c26196c4a5ddde9/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/RemoteEndpoint.java#L217 and https://github.com/eclipse/lsp4j/blob/89b5cd23def0abbd36e020440c26196c4a5ddde9/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/RemoteEndpoint.java#L233 for cancellations, and does the main request processing https://github.com/eclipse/lsp4j/blob/main/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/RemoteEndpoint.java#L257. At some point we have to start researching whether it’s outside of the CompletableFuture code, in the message i/o.

👀 1
👍 1
borkdude20:09:45

@jacob.maine Are you using emacs?

yes 1
borkdude20:09:02

So, one more attempt at explaining how I can reproduce it: type a series of x-es, then stop briefly and then hold backspace. If you can reproduce it, you will see several x-es at once be removed. Try this with very brief pauses (100-200ms, this probably relates to some delay that requests are being kicked off). Also try the same with lsp-mode turned off, it will feel more smoothly

borkdude20:09:04

Just hold the x button so multiple x-es will appear

jacob.maine20:09:13

> Try this with very brief pauses which part?

borkdude20:09:42

hold x button: 15 x-es or so will appear. Then pause briefly (100-200ms or so). Then hold backspace.

👌 1
borkdude20:09:47

Repeat this several times

borkdude20:09:08

I really appreciate the efforts guys

borkdude20:09:19

and I think it already feels a bit better than before

borkdude20:09:48

you might need to take longer pauses than 200ms, just try different things, but holding x (so multiple xs appear) and then holding backspace is what helps me to reproduce it

jacob.maine21:09:44

So strange. I can’t reproduce it. I copied your LSP config as closely as I could and I have the same lsp-doctor output as you. Have to be afk for a bit

👍 2
borkdude21:09:18

But you were able to reproduce the earlier problems right?

borkdude21:09:32

Going to sleep here and will do my work with the nightly tomorrow to see if the problem annoys me in real life usage

borkdude21:09:43

Btw, I'm using lspmode LSP :: lsp-mode <tel:202206202056|20220620.2056>, Emacs 28.1, darwin

borkdude21:09:48

Not sure if this matters?

borkdude21:09:54

could try an upgrade

ericdallo21:09:12

latest lsp-mode has lsp-clojure-trace-enable which can help with future debuggings

borkdude21:09:33

ok, installed that, no difference. the delay is really subtle now, maybe not enough to continue down the rabbit hole, but I'll see tomorrow.

👍 1
borkdude21:09:11

My hardware is m1 macbook air btw

🐧 1
borkdude21:09:50

I haven't tried asahi linux yet ;)

😄 1
borkdude21:09:02

Btw, now that we're trying out nightlies, please try the new :unused-value linter as well ;)

🚀 1
jacob.maine21:09:47

> you were able to reproduce the earlier problems right? Sort of. I could very occasionally get a small amount of lag. But it was less reproducible than what you’re experiencing now. Now I can’t really get any lag.

1
ericdallo21:09:53

@jacob.maine is there any way to get the parallelism level for each one of us and compare?

borkdude21:09:01

I also tried without lsp now, I might be seeing something else, so let me just try tomorrow with some fresh eyes, with and without lsp and then see if I will notice anything in real usage. I might have been focusing on some emacs artifact right now.

borkdude21:09:51

What I noticed when trying to disable lsp, is when I type lsp-mode lsp mode is disabled, but lsp-lens-mode is still enabled, this was a bit confusing

ericdallo21:09:37

What is the output of (java.util.concurrent.ForkJoinPool/getCommonPoolParallelism) for your mac?

ericdallo21:09:52

I know mine is 7 and Jacob's 3

ericdallo21:09:33

sounds like a minor bug on lsp-mode, where it's not disabling lens-mode as well

borkdude21:09:53

Ah darn, after executing lsp-workspace-shutdown typing (defn xxxxxxxxxxxxxx) is so much smoother :(

😔 1
borkdude21:09:30

I get 7

😮 1
borkdude21:09:16

Chip:	Apple M1
  Total Number of Cores:	8 (4 performance and 4 efficiency)

ericdallo21:09:41

so there is really something there... we have the same parallelism level, my emacs runs smoothly with no freeze during typing/backspacing, and I have lsp-idle-delay set to 0.2 which should make things slower in tradeoff of a better UI xp

ericdallo21:09:07

one thing I do have differently is emacs 28.2 with native compile enabled, but I really don't think that would make that different for this specific issue.

borkdude21:09:27

I went back to the lsp4j version and it's as smooth as when not running lsp

1
jacob.maine22:09:33

@U04V15CAJ something to check tomorrow… I sometimes see momentary freezes when Emacs does garbage collection. (I’m watching top while holding x or delete.) Is that when your freezes are too? I’m not sure why the lsp4j version would generate less garbage, but it’s worth checking.

jacob.maine22:09:28

Along this same line what’s your gc-cons-threshold set to? I know your config says 100MB; I have the same thing in my config. But when I check its value after startup, it’s about 30MB, so something else must be resetting it. Perhaps yours is getting changed too

borkdude09:09:51

@jacob.maine

ELISP> gc-cons-threshold
104857600 (#o620000000, #x6400000)

jacob.maine16:09:38

If I run lsp-server-clojure-log I can reproduce serious freezes, like the ones you’re seeing @U04V15CAJ… My guess is that creates a huge amount of garbage, and the freezes are Emacs GC pauses. To corroborate that, Emacs takes ~200MB of RAM without the log tail, but about 1.1GB with it. It must be under a lot more GC pressure. Are you tailing the log in Emacs? Are you starting clojure-lsp with tracing? If so, that’d be one reason why the lsp4j version generates much less garbage—it doesn’t have tracing turned on.

borkdude16:09:15

I don't think I have tracing on...

borkdude16:09:20

but I am logging

borkdude16:09:28

I don't have the log opened

borkdude16:09:47

This is my config:

{:copy-kondo-configs? false
 :log-path "/tmp/clojure-lsp.out"}
but this is server side, not something emacs is concerned with right

ericdallo16:09:59

yep, it should not be a problem unless you manually open that buffer or run lsp-server-clojure-log

borkdude16:09:14

ELISP> lsp-clojure-trace-enable
nil

jacob.maine16:09:59

Correct… that’s config for the server and tells it where to put the log. The client can ask the server what its log path is, so that it can open a buffer for it, which is, I think, what lsp-server-clojure-log does. There’s also another log, the log of what the client is doing. @ericdallo is that lsp-workspace-show-log? They contain similar information, but with different perspectives. A message that the client sends is logged on both sides, on the client side as a Sending… trace line, and on the server side as a Received… line

👍 1
ericdallo16:09:39

lsp-log-io for client logging from lsp-mode

jacob.maine16:09:25

What command are you using to start clojure-lsp? There was a moment there where I think you were adding --trace. What’s that variable called @ericdallo?

ericdallo16:09:53

lsp-clojure-server-command ?

lread14:10:15

One thing that is not totally clear to me (might of missed it, apologies if it is stated above) is if you are all trying to reproduce the problem on the same source that borkdude is. Are you all trying the xxxxxx test on analyzer.clj from clj-kondo?

lread14:10:14

When you folks talk about garbage collection, is this at all related to to JVM GC? (or rather GraalVM native image GC?). Or are you only talking about Emacs GC?

ericdallo14:10:49

I tested on compiler.cljc of squint as his original post

lread14:10:26

Thanks! Is there a theory as to why the switch to lsp4clj might have affected emacs GC? Or is this at the stage of looking at symptoms and just trying to diagnose what’s up?

ericdallo14:10:10

Yeah, I can't see why changing from lsp4j would affect emacs GC

borkdude14:10:16

I think this question is the thing that Jacob and I were left with last time since we could not reproduce the lag with VSCode

ericdallo14:10:42

(BTW just tested the xxxxx with delays and quick typing on clj-kondo analyzer.clj and can't repro the issue as well)

lread14:10:19

Are lsp4j and lsp4clj implementing exactly the same protocol? Could stress/flow tests be built and run against each to see where they behave differently?

lread14:10:24

(sorry I don’t know much about lsp4j or lsp4clj yet)

ericdallo14:10:19

no, lsp4j uses futures and it's java way while we do in clojure using promesa. There was a missing place where me and @jacob.maine talked about taking a look that was the IO processing, we don't think that is the issue, but it's the only thing a little bit more different than lsp4j

borkdude14:10:31

btw, this problem does strongly correlate with the size of the buffer for me

ericdallo14:10:23

yeah, makes sense as we send whole buffer to clj-kondo analyze when changing, but we do cancel futures now which we were not doing on latest release

borkdude14:10:59

I can even reproduce this by just typing () (the last paren is inserted automatically) and then backspace and then again, in a big buffer.

ericdallo14:10:26

yeah, your gif is really different than mine, it must be something with emacs :thinking_face:

lread14:10:26

A while back I wanted to test rewrite-clj against a large source file. The biggest one I found at the time was: https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/core.cljs. It is currently over 12k lines long. Might be a good candidate for large file testing?

👍 1
ericdallo14:10:50

metabase is usually a good candidate as well, but squint seems enough

borkdude14:10:08

> it must be something with emacs Then why are things very smooth with the version from before lsp4clj?

ericdallo14:10:20

good question 😂

ericdallo14:10:10

maybe try increase lsp-idle-delay for you

borkdude14:10:03

Switching to lsp-clojure-custom-server-command '("/Users/borkdude/bin/clojure-lsp-stable") is very noticeable...

borkdude14:10:12

I'll try that

lread14:10:18

@U04V15CAJ if you had time and patience, you could maybe try with @ericdallo’s https://github.com/ericdallo/dotfiles/tree/master/.doom.d and see if you get different results?

👍 1
borkdude14:10:11

sure. if it's just something I can clone and doesn't have any system-specific assumptions...?

borkdude14:10:33

upping lsp-idle-delay to 1s doesn't help

lread14:10:02

Or… maybe @ericdallo if you have time and patience, you could try @U04V15CAJ’s emacs config?

👍 1
borkdude14:10:45

I see the delay just after this lsp-idle-delay has passed, when I start typing just after that interval though, I think

ericdallo14:10:53

Yes, my config should be pretty good for starters IIRC, but I can try yours later tonight

🙏 1
lread14:10:11

Time and patience is probably a deciding factor for exploration here. simple_smile

👍 1
😄 1
ericdallo14:10:33

maybe could be other emacs package, I know that only happens changing clojure-lsp releases though

lread15:10:14

So we are all on the same page exactly what file are we doing the xxxxxx test on?

borkdude15:10:14

The xxxx test is: typing xxxxx, then pause briefly (I think the same period of time that lsp-idle-delay is set to), then continue typing. The xxxxes often don't appear smoothly, but are buffered and then appear in one go. Similarly when typing () and then backspace and then repeat.

lread15:10:16

And maybe we should be doing it all in the same place-ish? Near the top or bottom of the file? Does that matter?

borkdude15:10:33

The place does not matter for me, but the buffer size does

👍 2
lread15:10:46

> The xxxx test is: typing xxxxx, then pause briefly (I think the same period of time that lsp-idle-delay is set to), then continue typing. The xxxxes often don’t appear smoothly, but are buffered and then appear in one go. Similarly when typing () and then backspace and then repeat. Cool, and which source file? We should probably all be using the same one.

borkdude15:10:04

analyzer.clj in clj-kondo or src/squint/compiler.cljc will do

👍 1
borkdude15:10:58

I think the best way to describe this is that it's as if you're typing with sticky fingers

jacob.maine17:10:54

@UE21H2HHD, can I invite you to https://clojurians.slack.com/archives/CPABC1H61/p1663620137210819. It’s the same discussion, but I’d prefer to have one thread to monitor

😂 3
👍 3