microsoft / microsoft/vscode-cpptools
Constant CPU usage from cpptools.exe scanning workspace
Nessuno ha ancora preso questa issue.
- Lingua principale
- TypeScript
- Stelle
- 6.2k
- Fork
- 1.7k
- Merge medio
- 14h 46m
- PR unite (30g)
- 61
Descrizione
On Windows, simply having VS Code open on a folder with a C++ project causes the cpptools.exe to almost constantly use some CPU. It doesn't use a full CPU core, but enough to occasionally make my laptop fan spin up.
The offending stack trace starts with
msvc::recursive_directory_iterator_utf8::enumerate_files_non_recursive
msvc::recursive_directory_iterator_utf8::recursive_directory_iterator_utf8
browse_engine::query_include_path_suggestions_impl
browse_engine::parse_file
browse_engine::parse_root
cpptools_context::parse_root
std::_Func_impl_no_alloc<`cpptools_context::cpptools_context'::`1'::<lambda_10_>,void,cpptools_context::browse_engine_update_action_and_task_token &&>::_Do_call
`msvc::deque_thread<cpptools_context::browse_engine_update_action_and_task_token>::defer'::`2'::<lambda_1>::operator()
msvc::thread_manager_t::do_work
msvc::thread_helper_t::thread_entry
thread_start<unsigned int (__cdecl*)(void *),1>
from there, it calls FindNextFileW() to iterate over the contents of the directory, and GetFileAttributesExW() presumably to get the modification time for each file. (Without having access to the cpptools executable I'm having to guess at why these calls are made).
The calls to GetFileAttributesExW end up taking a disproportionate amount of time, and I don't think they're necessary.
The FindNextFile function already returns attributes on each file, so GetFileAttributesEx() seems redundant. Alternatively, this could all be replaced with a call to GetFileInformationByHandleEx(), and both approaches would be over an order of magnitude faster. See the following blog post which documents optimizing pretty much the exact same use case:
https://www.wholetomato.com/blog/2024/11/14/how-to-query-file-attributes-50x-faster-on-windows/
I'd love to submit a PR myself, but again, I don't have access to the cpptools executable's source code.
I hope you can take a look at this. Even if the extension only uses a few percent CPU, doing so constantly on every machine it's running on adds up to a lot of wasted time and energy, if it can be trivially sped up.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia individuando l’implementazione alla base di msvc::recursive_directory_iterator_utf8 e browse_engine::query_include_path_suggestions_impl, quindi segui il loro utilizzo di FindNextFileW e GetFileAttributesExW. Confronta la scansione delle directory esistente con le API Windows suggerite e conferma che la modifica riduce il lavoro ripetuto di recupero degli attributi dei file e l’uso costante della CPU in un workspace C++ Windows.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- cpp, typescript
- Ambito
- performance, tooling
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Attiva
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100