GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — HttpStatus.resolve allocates HttpStatus.values() once per invocation · Issue #26842 · spring-projects/spring-framework

HttpStatus.resolve allocates HttpStatus.values() once per invocation #26842

New issue
Copy link
New issue
Copy link
Closed
Closed
HttpStatus.resolve allocates HttpStatus.values() once per invocation#26842
Copy link
Assignees
poutsma
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement
Milestone
5.3.7

Description

@richardstartin
richardstartin
opened on Apr 21, 2021
Issue body actions

I just noticed looking at profiles of some reactor based benchmarks we run to measure Datadog tracer overhead that HttpStatus.resolve allocates an HttpStatus[] once per invocation, so once per response. In a very modest throughput benchmark (~600rps) this is allocating 1MB/s just to resolve the integer status code to the HttpStatus enum value.
Screenshot 2021-04-21 at 22 35 38

I tracked the spring framework code down here.

This could be fixed by caching HttpStatus.values() in an array, which could be iterated over as many times as one likes without any further allocation.

Reacted by Oliver Weiler, Arash Shahkar, Denis Tunović, Sylvain Brocard, Kwangyong Kim, Suresh, Ding Guangyu, Alex Ciminian, sunny klair, Petr Janeček and 5 more

Activity

  1. spring-projects-issues
    added
    status: waiting-for-triageAn issue we've not yet triaged or decided on
    on Apr 21, 2021
  2. poutsma
    self-assigned this
    on Apr 22, 2021
  3. poutsma
    added
    in: webIssues in web modules (web, webmvc, webflux, websocket)
    type: enhancementA general enhancement
    and removed
    status: waiting-for-triageAn issue we've not yet triaged or decided on
    on Apr 22, 2021
  4. poutsma
    added this to the 5.3.7 milestone on Apr 22, 2021
  5. poutsma commented on Apr 22, 2021

    @poutsma
    poutsma
    on Apr 22, 2021
    Contributor
    More actions

    I think we can do better than a cached array, and might as well start using a Map<Integer, HttpStatus>.

  6. richardstartin commented on Apr 22, 2021

    @richardstartin
    richardstartin
    on Apr 22, 2021
    Author
    More actions

    Boxing HTTP status codes can be problematic because the common ones all fall outside the range of the Integer cache. We use this data structure for representing mappings between small, sparse finite sets of integers (such as status codes or ports) and arbitrary things, which works very well for tracing, and something similar may be applicable here.

    Reacted by Suresh
  7. poutsma commented on Apr 22, 2021

    @poutsma
    poutsma
    on Apr 22, 2021
    Contributor
    More actions

    Thanks you for help.

    I am not sure if we want to introduce a new data structure into the framework to resolve this. I'll make a copy of the array instead, as originally suggested.

  8. poutsma
    closed this as completedin 7f10621on Apr 22, 2021
  9. richardstartin commented on Apr 22, 2021

    @richardstartin
    richardstartin
    on Apr 22, 2021
    Author
    More actions

    That makes sense - we don't record any time spent in HttpStatus.resolve at all, it only shows up for the allocations.

  10. sbrannen
    added a commit that references this issue on May 13, 2021

    Fix grammar in inline comment in HttpStatus

    fae4848
  11. lxbzmy
    added 2 commits that reference this issue on Mar 26, 2022

    Copy HttpStatus::values to prevent allocation

    This issue will close once commit 35e2795 is merged into the 'main' branch.
    35e2795

    Fix grammar in inline comment in HttpStatus

    This issue will close once commit 72e1eeb is merged into the 'main' branch.
    72e1eeb
  12. houxianghui
    added a commit that references this issue on Sep 17, 2026

    Copy HttpStatus::values to prevent allocation

    This issue will close once commit 7f10621 is merged into the 'master' branch.
    7f10621
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @poutsma
    poutsma

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

    Milestone

    • 5.3.7

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.