Skip to content
  • Matt Whitlock's avatar
    respect file priority when selecting preview chunks · 852b0b4b
    Matt Whitlock authored
    Previously, ChunkSelector would select preview chunks ahead of all
    other chunks, regardless of file priority. This meant that files
    prioritized as "Last" would nevertheless have all of their preview
    chunks downloaded before all files prioritized as "First" or "Normal"
    had finished downloading. This contradicts user expectation, which is
    that scarce download bandwidth should not be devoted to files marked
    "Last" until all files prioritized as "First" and "Normal" have been
    completely downloaded.
    
    This commit splits the existing PREVIEW_PRIORITY level into three
    priority levels: FIRST_PREVIEW_PRIORITY, NORMAL_PREVIEW_PRIORITY, and
    LAST_PREVIEW_PRIORITY. Chunks that ChunkManager determines to be
    preview chunks have their priority levels boosted to the preview
    priority level corresponding to their respective base priority level.
    
    ChunkSelector's algorithm receives an overhaul that eliminates the
    temporary std::list objects in favor of remembering the best (highest
    priority, least number of downloaders) chunk during the iteration and
    selecting that chunk if no chunk at the same priority level but with
    no downloaders is found. The logic is ultimately equivalent to that
    implemented in leastPeers(…) but will run faster since it requires no
    heap allocations. Also, the new algorithm will not fail to select a
    chunk that already has downloaders if there are no chunks that have no
    downloaders. This should keep PieceDownloaders busier.
    852b0b4b