pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

Pylance Syntax Highlighting isnot working or working very slow

Open f1den opened this issue 9 months ago • 25 comments

Environment data

  • Pylance version: 2025.2.100
  • OS and version: Win 10 Pro 19045.3208 22H2
  • Python version: 3.11.2 x64
  • VS Code version: 1.97.2

Code Snippet

def foo(a: str, b: str) -> str:
  c = a + " " + b
  print(c)
  return c

def main() -> None:
  foo("Hello", "World")

Expected behavior

syntax highlighted fast

Actual behavior

syntax is making same thing but with python, also variables are not correctly highlighted (This gif is from another guy in cpp, but i have same thing with python) Image

EVEN With code snipped i provided as single file in project folder Here is some ss:

Image Image

Also take a look at comment highlighting (screenshot is made after ~ one minute)

Image

Logs

nothing outputed :<

f1den avatar Feb 19 '25 11:02 f1den

Thanks for the issue. Can you include the logs for pylance as described here?

https://github.com/microsoft/pylance-release/blob/main/TROUBLESHOOTING.md#filing-an-issue

rchiodo avatar Feb 19 '25 17:02 rchiodo

issue_pylance_output.txt

code in callback_parser.py:

from telethon import TelegramClient
from telethon import events

API_ID = '12'
API_HASH = '12'
print("halo2")
print("\n\n")
print("hmm..\n")
client = TelegramClient('cheba_acc', API_ID, API_HASH)


async def main():
    print("Hello, starting bot..")
    me = await client.get_me()
    print(me.stringify())
    username = me.username
    print(username)

@client.on(events.NewMessage())
async def handler(event: events.NewMessage.Event):
    msg = event.message
    if msg.out:
        return
    print(msg)

with client:
    client.loop.run_forever()

f1den avatar Feb 20 '25 15:02 f1den

Also log after i commented line:

Image

2025-02-20 18:31:37.844 [info] [Info  - 6:31:37 PM] (23236) SourceFile: Received fs event 'change' for path 'f:\work\cheba_2_bots\callback_parser.py'
2025-02-20 18:31:41.441 [info] (23236) [FG] parsing: file:///f%3A/work/cheba_2_bots/callback_parser.py (1ms)
2025-02-20 18:31:41.441 [info] (23236) [FG] binding: file:///f%3A/work/cheba_2_bots/callback_parser.py (0ms)
2025-02-20 18:32:15.793 [info] [Info  - 6:32:15 PM] (23236) SourceFile: Received fs event 'change' for path 'f:\work\cheba_2_bots\callback_parser.py'
2025-02-20 18:33:00.943 [info] (23236) [BG(1)] SemanticTokens delta previousResultId:1740065416772 at file:///f%3A/work/cheba_2_bots/callback_parser.py (138104ms)
2025-02-20 18:33:00.943 [info] [Info  - 6:33:00 PM] (23236) [BG(1)] Long operation: SemanticTokens delta previousResultId:1740065416772 at file:///f%3A/work/cheba_2_bots/callback_parser.py (138104ms)
2025-02-20 18:33:00.946 [info] (23236) [BG(1)] indexing: file:///f%3A/work/cheba_2_bots/callback_parser.py ...
2025-02-20 18:33:00.946 [info] (23236) [BG(1)]   parsing: file:///f%3A/work/cheba_2_bots/callback_parser.py (2ms)
2025-02-20 18:33:00.946 [info] (23236) [BG(1)]   binding: file:///f%3A/work/cheba_2_bots/callback_parser.py (0ms)
2025-02-20 18:33:00.947 [info] (23236) [BG(1)] indexing: file:///f%3A/work/cheba_2_bots/callback_parser.py [found 5] (2ms)
2025-02-20 18:33:00.947 [info] (23236) Workspace indexing done: file:///f%3A/work/cheba_2_bots/callback_parser.py

f1den avatar Feb 20 '25 15:02 f1den

Wow this:

2025-02-20 18:33:00.943 [info] [Info  - 6:33:00 PM] (23236) [BG(1)] Long operation: SemanticTokens delta previousResultId:1740065416772 at file:///f%3A/work/cheba_2_bots/callback_parser.py (138104ms)

Hopefully it will reproduce for us with the same code. I would hazard a guess whatever the telethon package is, it doesn't have any type annotations and is taking a long time to analyze (semantic tokens require type information).

rchiodo avatar Feb 20 '25 17:02 rchiodo

but i had no issue month ago, worked with telethon, opencv, and others. but now i have the problem :<

f1den avatar Feb 20 '25 17:02 f1den

We do make changes in our underlying type evaluator, one of those could have regressed analysis of telethon. We have limits on searching for types and increasing those so some other package would finish analysis could have potentially caused telethon to take a lot longer. I'm trying to reproduce it right now.

rchiodo avatar Feb 20 '25 17:02 rchiodo

For me it's not quite as bad:

2025-02-20 09:22:53.982 [info] [Info  - 9:22:53 AM] (4049084) [BG(1)] Long operation: analyzing: 
file:///c%3A/Users/rchiodo/source/testing/test_pylance/test_telethon_semantic_colors.py (2941ms)

Oh wait, that's with the comment. Uncommenting the print makes it take a LOT longer.

If I turn on perf logging I can see this function is a main culprit:

2025-02-20 09:27:51.865 [info] (4049084) [BG(1)]            [Function 'pretty_format' (telethon.tl.tlobject)] (837ms)
2025-02-20 09:27:52.651 [info] (4049084) [BG(1)]            [Function 'pretty_format' (telethon.tl.tlobject)] (787ms)
2025-02-20 09:27:53.415 [info] (4049084) [BG(1)]            [Function 'pretty_format' (telethon.tl.tlobject)] (764ms)
2025-02-20 09:27:54.250 [info] (4049084) [BG(1)]            ...
2025-02-20 09:27:54.250 [info] (4049084) [BG(1)]              [Function 'pretty_format' (telethon.tl.tlobject)] (834ms)
2025-02-20 09:27:55.026 [info] (4049084) [BG(1)]              [Function 'pretty_format' (telethon.tl.tlobject)] (776ms)
2025-02-20 09:27:55.774 [info] (4049084) [BG(1)]              [Function 'pretty_format' (telethon.tl.tlobject)] (748ms)
2025-02-20 09:27:57.417 [info] (4049084) [BG(1)]              [Function 'pretty_format' (telethon.tl.tlobject)] (1644ms)
2025-02-20 09:27:58.184 [info] (4049084) [BG(1)]              [Function 'pretty_format' (telethon.tl.tlobject)] (766ms)
2025-02-20 09:27:58.910 [info] (4049084) [BG(1)]              [Function 'pretty_format' (telethon.tl.tlobject)] (725ms)
2025-02-20 09:27:59.746 [info] (4049084) [BG(1)]              [Function 'pretty_format' (telethon.tl.tlobject)] (836ms)
2025-02-20 09:28:01.634 [info] (4049084) [BG(1)]              [Function 'pretty_format' (telethon.tl.tlobject)] (1889ms)
2025-02-20 09:28:02.341 [info] (4049084) [BG(1)]              [Function 'pretty_format' (telethon.tl.tlobject)] (706ms)
2025-02-20 09:28:03.190 [info] (4049084) [BG(1)]              [Function 'pretty_format' (telethon.tl.tlobject)] (850ms)
2025-02-20 09:28:04.083 [info] (4049084) [BG(1)]              [Function 'pretty_format' (telethon.tl.tlobject)] (893ms)
2025-02-20 09:28:05.779 [info] (4049084) [BG(1)]              [Function 'pretty_format' (telethon.tl.tlobject)] (1696ms)
2025-02-20 09:28:06.645 [info] (4049084) [BG(1)]              [Function 'pretty_format' (telethon.tl.tlobject)] (865ms)
2025-02-20 09:28:07.615 [info] (4049084) [BG(1)]              [Function 'pretty_format' (telethon.tl.tlobject)] (971ms)
2025-02-20 09:28:08.346 [info] (4049084) [BG(1)]              [Function 'pretty_format' (telethon.tl.tlobject)] (731ms)
2025-02-20 09:28:10.165 [info] (4049084) [BG(1)]              [Function 'pretty_format' (telethon.tl.tlobject)] (1819ms)
2025-02-20 09:28:10.923 [info] (4049084) [BG(1)]              [Function 'pretty_format' (telethon.tl.tlobject)] (757ms)
2025-02-20 09:28:11.666 [info] (4049084) [BG(1)]              [Function 'pretty_format' (telethon.tl.tlobject)] (744ms)
2025-02-20 09:28:12.420 [info] (4049084) [BG(1)]              [Function 'pretty_format' (telethon.tl.tlobject)] (754ms)
2025-02-20 09:28:14.210 [info] (4049084) [BG(1)]              [Function 'pretty_format' (telethon.tl.tlobject)] (1789ms)
2025-02-20 09:28:15.058 [info] (4049084) [BG(1)]              [Function 'pretty_format' (telethon.tl.tlobject)] (848ms)

I tried adding type annotations to that function, but it's still slow. @erictraut do you have any ideas?

rchiodo avatar Feb 20 '25 17:02 rchiodo

For me it's not quite as bad:

You can try to make it several times and you will see same time as mine, or even longer

also it's not only "print" issue, anything i touch in this file takes lot of time to finish

f1den avatar Feb 20 '25 17:02 f1den

Wondering if this might be related to my recent changes to add the callable semantic modifier. Eric had warned us that implementing that feature would require type evaluation and might result in perf issues. There are now three places in semanticTokenProvider.ts where we call getType(), but only one of them (for TokenTypes.property) is new. You could try commenting out the code added in https://github.com/microsoft/pyrx/pull/6284 and see if the perf improves.

debonte avatar Feb 20 '25 19:02 debonte

You could try commenting out the code added in https://github.com/microsoft/pyrx/pull/6284 and see if the perf improves.

if this was for me, i can't access it :D

f1den avatar Feb 24 '25 11:02 f1den

if this was for me, i can't access it :D

Sorry, no, I was talking to @rchiodo.

debonte avatar Feb 24 '25 18:02 debonte

I encountered the same problem. When I enable pylance, the syntax highlighting of code is slow, even very simple code and no python interpreter. However, if I disable pylance, it goes well. I think it will be easier to be reproduced when the max CPU frequency is limited to 80% or 70%. I found that even I comment only one line, the CPU frequency will reach its maximum value. Enable: It looks like some part of code changes instantly and others changes slowly. Image

Disable: The syntax highlighting of the code changes instantly. Image

tokenet avatar Feb 28 '25 06:02 tokenet

I encountered the same problem.

It is ok for highlighting update to take ~<2 sec. So there is no issue in your case. it is normal behavior (maybe)

P.S. I was waithing 60+ seconds :D

f1den avatar Mar 03 '25 09:03 f1den

I have observed the same problem despite having an extremely beefy CPU. I do tend to work on very large codebases but Pylance syntax highlighting is getting very slow, slower than it used to be.

umarbutler avatar Apr 08 '25 12:04 umarbutler

Can any of you provide a code sample that reproduces this behavior?

debonte avatar Apr 08 '25 17:04 debonte

any telethon(lib) code that could run.

f1den avatar Apr 12 '25 11:04 f1den

issue_pylance_output.txt

code in callback_parser.py:

from telethon import TelegramClient from telethon import events

API_ID = '12' API_HASH = '12' print("halo2") print("\n\n") print("hmm..\n") client = TelegramClient('cheba_acc', API_ID, API_HASH)

async def main(): print("Hello, starting bot..") me = await client.get_me() print(me.stringify()) username = me.username print(username)

@client.on(events.NewMessage()) async def handler(event: events.NewMessage.Event): msg = event.message if msg.out: return print(msg)

with client: client.loop.run_forever()

this code was in issue as example

f1den avatar Apr 26 '25 13:04 f1den

this code was in issue as example

Here's what I tried:

  1. Create a new directory
  2. Create a venv
  3. pip install telethon
  4. Create test.py and paste in the code above.

That on its own is not enough to reproduce the issue for me. Semantic highlighting isn't lightning-fast, but it's less than a second.

If you do the same, do you see semantic highlighting taking longer?

debonte avatar Apr 29 '25 17:04 debonte

This issue has been closed automatically because it needs more information and has not had recent activity. If the issue still persists, please reopen with the information requested. Thanks.

github-actions[bot] avatar May 30 '25 11:05 github-actions[bot]

@debonte I was able to reproduce the issue. You can see it in my logs above.

Essentially I copied the original poster's code, then commented and uncommented this line here:

from telethon import TelegramClient
from telethon import events

API_ID = '12'
API_HASH = '12'
print("halo2")
print("\n\n")
print("hmm..\n")
client = TelegramClient('cheba_acc', API_ID, API_HASH)


async def main():
    print("Hello, starting bot..")
    me = await client.get_me()
    print(me.stringify()) # <--- Comment and uncomment this line
    username = me.username
    print(username)

@client.on(events.NewMessage())
async def handler(event: events.NewMessage.Event):
    msg = event.message
    if msg.out:
        return
    print(msg)

with client:
    client.loop.run_forever()

rchiodo avatar Jun 03 '25 16:06 rchiodo

@debonte I was able to reproduce the issue. You can see it in my logs above.

Essentially I copied the original poster's code, then commented and uncommented this line here:

@rchiodo, for me it's a little sluggish, but definitely less than 1 second. Nothing like what the OP was saying -- "(screenshot is made after ~ one minute)"

debonte avatar Jun 03 '25 17:06 debonte

Yeah for me uncommenting (or commenting) takes a couple of seconds for an update.

https://github.com/user-attachments/assets/87ba0b0f-1910-448c-b943-20cc842da087

rchiodo avatar Jun 03 '25 17:06 rchiodo

Might be a difference in our settings? I'm on defaults for everything except that typeCheckingMode is set to standard.

debonte avatar Jun 03 '25 17:06 debonte

I only have 'autoImportCompletions' enabled. I'm guessing it's more how much stuff is in my venv. I'm doing this in a venv that has a ton of other packages.

rchiodo avatar Jun 03 '25 18:06 rchiodo

I wonder what it is like if we disable full semantic token and only enable partial semantic token

heejaechang avatar Jun 03 '25 18:06 heejaechang

This issue has been closed automatically because it needs more information and has not had recent activity. If the issue still persists, please reopen with the information requested. Thanks.

github-actions[bot] avatar Jul 04 '25 11:07 github-actions[bot]