New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HttpStatus.resolve allocates HttpStatus.values() once per invocation #26842
Comments
I think we can do better than a cached array, and might as well start using a |
Boxing HTTP status codes can be problematic because the common ones all fall outside the range of the |
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. |
That makes sense - we don't record any time spent in |
Before this commit, HttpStatus::resolve used the values() method in its logic. This causes a new array to be allocated for each invocation, and results in memory overhead. This commit makes a copy of the HttpStatus values array, and uses that to resolve status codes. Closes spring-projectsgh-26842
Before this commit, HttpStatus::resolve used the values() method in its logic. This causes a new array to be allocated for each invocation, and results in memory overhead. This commit makes a copy of the HttpStatus values array, and uses that to resolve status codes. Closes spring-projectsgh-26842
I just noticed looking at profiles of some reactor based benchmarks we run to measure Datadog tracer overhead that
HttpStatus.resolve
allocates anHttpStatus[]
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 theHttpStatus
enum value.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.The text was updated successfully, but these errors were encountered: