Skip to content

qbs session uses CPU #1

@arBmind

Description

@arBmind

Observation:

  • QtCreator spawns multiple qbs session processes
  • On Windows each qbs session process consumes a .1-.3 % of my CPU when idle. With 4 processes this doubles the idle usage of my laptop and is a huge waste of battery.

Goals:

  • Do not drain my battery / consume idle power
  • Reduce extra processes and communication overhead

Analysis:

  • qbs session communicates over stdin and stdout with host process (QtCreator)
  • uses a QTimer to check if data was sent every 10ms
  • A qbs session process is spawned for each project configuration (Up to 4 per project - I guess debug/release and 2nd config)
  • clangbackend is not measurable on idle.
    • uses seperate named pipe (non blocking socket)
    • stdio is forwarded to qtcreator (not used for communication)
    • custom QDataStream based encoding (only useful for Qt environments)
  • clangd used by VsCode is not measurable on idle.
    • simple use of blocking stdin
    • mitigates debugger interrupts (see clang-tools-extra/clangd/JSONTransport.cpp)
    • seems to spawn threads for actual work

Experiments on qbs:

  • Even waiting for 90ms effectively brick qbs.
  • Using singleShot timer might help for sleeping. But does not stop idle drain.

Perfect solution:

  • Write a dedicated qbsd
  • use approach from clangd with blocking stdin reading
  • spawn/communicate with thread per session
  • hope: qbscore was doing something similar when it was part of qtcreator?
  • possible challenges:
    • protocol needs to be extended by something like a sessionId, start and end of sessions.
    • qtcreator needs to hold a common instance and despawn qbsd when not needed

Hacking solution:

  • Use worker thread in qbs to read stdin blockingly
  • Abort thread by closing stdin
  • Process received data with signals

Alternatives:

  • Use CompletionIO for Windows
    • Would require adding completion IO support to Qt main loop (might not be actually hard, but requires very careful design)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions