pylance-release
pylance-release copied to clipboard
Pylance Syntax Highlighting isnot working or working very slow
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)

EVEN With code snipped i provided as single file in project folder Here is some ss:
Also take a look at comment highlighting (screenshot is made after ~ one minute)
Logs
nothing outputed :<
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
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()
Also log after i commented line:
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
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).
but i had no issue month ago, worked with telethon, opencv, and others. but now i have the problem :<
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.
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?
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
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.
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
if this was for me, i can't access it :D
Sorry, no, I was talking to @rchiodo.
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.
Disable:
The syntax highlighting of the code changes instantly.
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
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.
Can any of you provide a code sample that reproduces this behavior?
any telethon(lib) code that could run.
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
this code was in issue as example
Here's what I tried:
- Create a new directory
- Create a venv
pip install telethon- Create
test.pyand 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?
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.
@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()
@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)"
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
Might be a difference in our settings? I'm on defaults for everything except that typeCheckingMode is set to standard.
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.
I wonder what it is like if we disable full semantic token and only enable partial semantic token
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.