Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pylance Syntax Highlighting isnot working or working very slow #6962

Open
f1den opened this issue Feb 19, 2025 · 12 comments
Open

Pylance Syntax Highlighting isnot working or working very slow #6962

f1den opened this issue Feb 19, 2025 · 12 comments
Assignees
Labels
perf user responded Was "waiting for user response" and they responded

Comments

@f1den
Copy link

f1den commented Feb 19, 2025

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 :<
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Feb 19, 2025
@rchiodo
Copy link
Contributor

rchiodo commented Feb 19, 2025

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 rchiodo added the waiting for user response Requires more information from user label Feb 19, 2025
@f1den
Copy link
Author

f1den commented Feb 20, 2025

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()

@github-actions github-actions bot added user responded Was "waiting for user response" and they responded and removed waiting for user response Requires more information from user labels Feb 20, 2025
@f1den
Copy link
Author

f1den commented Feb 20, 2025

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

@rchiodo
Copy link
Contributor

rchiodo commented Feb 20, 2025

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).

@f1den
Copy link
Author

f1den commented Feb 20, 2025

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

@rchiodo
Copy link
Contributor

rchiodo commented Feb 20, 2025

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
Copy link
Contributor

rchiodo commented Feb 20, 2025

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 rchiodo added perf and removed needs repro Issue has not been reproduced yet labels Feb 20, 2025
@f1den
Copy link
Author

f1den commented Feb 20, 2025

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

@debonte
Copy link
Contributor

debonte commented Feb 20, 2025

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.

@f1den
Copy link
Author

f1den commented Feb 24, 2025

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

@debonte
Copy link
Contributor

debonte commented Feb 24, 2025

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

Sorry, no, I was talking to @rchiodo.

@tokenet
Copy link

tokenet commented Feb 28, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf user responded Was "waiting for user response" and they responded
Projects
None yet
Development

No branches or pull requests

5 participants