fix: read request body correctly#134
Merged
savonarola merged 1 commit intoemqx:masterfrom Jul 22, 2025
Merged
Conversation
6e1a9f1 to
35dae3f
Compare
keynslug
approved these changes
Jul 22, 2025
src/minirest_body.erl
Outdated
Comment on lines
+114
to
+115
| {more, Bin, NewRequest} -> binary_decoder(NewRequest, [Bin | Acc]); | ||
| {ok, Bin, DoneRequest} -> {ok, iolist_to_binary(lists:reverse([Bin | Acc])), DoneRequest} |
Contributor
There was a problem hiding this comment.
Just wanted to chime in with previous experience.
Deep improper lists may show slightly better performance, likely due to less GC pressure. I.e.
Suggested change
| {more, Bin, NewRequest} -> binary_decoder(NewRequest, [Bin | Acc]); | |
| {ok, Bin, DoneRequest} -> {ok, iolist_to_binary(lists:reverse([Bin | Acc])), DoneRequest} | |
| {more, Bin, NewRequest} -> binary_decoder(NewRequest, [Acc | Bin]); | |
| {ok, Bin, DoneRequest} -> {ok, iolist_to_binary(Acc)), DoneRequest} |
GC Pressure @ 10k chunks of 400 bytes each
emqx_binacc_bench:accum_deep(Es) emqx_binacc_bench:accum_reverse(Es, [])
minor_gcs: 100 184
minor_gcs_duration: 773 5247
major_gcs: 0 0
major_gcs_duration: 0 0
heap_reclaimed: 2100919 2907062
offheap_bin_reclaimed: 50002500 50002475
stack_min: 5 4
stack_max: 5 6
Admittedly, this is pretty hard to prove in practice: simple synthetic microbenchmarks fluctuate between ~40% improvement in runtime to slight negative effect with around 10-15% improvement on average, depending on the choice of parameters. Which probably hints at memory allocation machinery complexity. So take it with a grain of salt.
eministat @ 10k chunks 400 bytes
x accrev / Fixed List 10k
+ deep / Fixed List 10k
+--------------------------------------------------------------------------+
|++*********xxxxx xx xxx xxxxx xxxx xxxxx x x|
|+++****** *xx x x x x xxx xx x xxxx |
|+++**+*** x x x x x x x x x |
| +++*+*** x x x x x x |
| +*+**x x x x x |
| +*+**x x x |
| +++**x |
| +++*+ |
| +++++ |
| +++++ |
| +++++ |
| + +++ |
| + ++ |
| ++ |
| ++ |
| ++ |
| ++ |
| ++ |
| ++ |
| ++ |
| ++ |
| ++ |
| + |
| + |
| |_______________A__M____________| |
| |_A_| |
+--------------------------------------------------------------------------+
Dataset: x N=100 CI=95.0000
Statistic Value [ Bias] (Bootstrapped LB‥UB)
Min: 1859.00
1st Qu. 2335.00
Median: 4175.00
3rd Qu. 5221.00
Max: 8858.00
Average: 3908.50 [ 0.290371] ( 3597.91 ‥ 4228.45)
Std. Dev: 1602.88 [ -9.82188] ( 1489.09 ‥ 1882.22)
Outliers: 0/0 = 0 (μ=3908.79, σ=1593.06)
Outlier variance: 0.989089 (severe, the data set is probably unusable)
------
Dataset: + N=100 CI=95.0000
Statistic Value [ Bias] (Bootstrapped LB‥UB)
Min: 1620.00
1st Qu. 1978.00
Median: 2137.00
3rd Qu. 2248.00
Max: 2566.00
Average: 2110.53 [ -0.248106] ( 2071.25 ‥ 2149.37)
Std. Dev: 196.815 [ -1.41853] ( 171.619 ‥ 227.719)
Outliers: 0/0 = 0 (μ=2110.28, σ=195.397)
Outlier variance: 0.769069 (severe, the data set is probably unusable)
Difference at 95.0% confidence
-1797.97 ± 316.524
-46.0015% ± 8.09836%
(Student's t, pooled s = 1141.92)
------
Contributor
Author
There was a problem hiding this comment.
Thanks for the insights, eministat visualizes significant difference, I changed the implementation.
However, this code is probably almost never called in practice 😅
35dae3f to
bd414bc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.