Skip to content

RFC Possible performance improvement for SPIRAM targets #8428

Description

@peterhinch

The time for GC on an ESP32 without SPIRAM is ~1.8ms. Add SPIRAM and it goes to 100ms, impacting the latency of the soft-only interrupts. This cliff edge leads me to avoid SPIRAM modules where possible. It would be good if there were a way to avoid it.

One approach might be for the user to be able to specify (perhaps in boot.py) the maximum SPIRAM to be made available in the pool, from 0 upwards in increments of (say) 1MB.

Another approach would be to automate this. Initially the pool would comprise only internal RAM. If an allocation would cause OOM, 1MB of SPIRAM would be added to the pool. This would continue until SPIRAM was exhausted. In this way an application would only use the amount of SPIRAM it actually required. GC would take place in the current pool, so in small applications SPIRAM would never be used and GC would be fast. Adding to the pool would be a one way process - once a 1MB block was added, it would remain in place until reset.

This is an illustration - there may well be better algorithms than the above. For example adding a block before OOM actually occurs might improve performance by reducing fragmentation.

Activity

  1. robert-hh commented on Mar 18, 2022

    @robert-hh
    Contributor

    Limiting the amount of SPIRAM for the heap might be the easier part, by starting with a small amount like 1M and being able to extend it once. Reducing it seems more complicated, if the heap is already populated.
    In any case, SPIRAM is subject to cache misses and therefore slow.

  2. peterhinch commented on Mar 19, 2022

    @peterhinch
    ContributorAuthor

    My thinking is based on the fact that boards like the UM Feather S2 have useful features, but include 8MB SPIRAM. For smaller, high performance applications, even the ability to disable SPIRAM in boot.py would be a big advantage. We win twice: with fast RAM and short GC time.

    Reducing it seems more complicated, if the heap is already populated.

    I don't envisage a need for this. The firmware would initialise with the heap restricted to internal RAM. The boot.py option (or algorithm) would only ever increase the size.

  3. peterhinch commented on Mar 25, 2022

    @peterhinch
    ContributorAuthor

    Here is a practical issue reported by a user. In a uasyncio application GC was causing 300ms of additional latency between pressing a button and getting a response.

  4. dpgeorge commented on Apr 22, 2022

    @dpgeorge
    Member

    Another approach would be to automate this. Initially the pool would comprise only internal RAM. If an allocation would cause OOM, 1MB of SPIRAM would be added to the pool. This would continue until SPIRAM was exhausted.

    I think this is a very good idea.

  5. tannewt commented on Sep 28, 2023

    @tannewt
    Sponsor

    This was done in #12141 and can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions