<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 15, 2018 at 12:07 PM, Jonas Falkevik <span dir="ltr"><<a href="mailto:jonas.falkevik@mobilearts.com" target="_blank">jonas.falkevik@mobilearts.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><span class="gmail-">> <br>
> <br>
> Interesting... I wonder if maybe it wouldn't be better to solve this problem in the code for realloc so that no copy is done when a realloc of the same size if issued... that way we solve it in all places instead of only in the inet_driver<br>
> <br></span><br></blockquote><div>Something like <a href="https://github.com/falkevik/otp/commit/444fb00ff2a9d1f40a8c66f48bea1cf3f07ca86c">https://github.com/falkevik/otp/commit/444fb00ff2a9d1f40a8c66f48bea1cf3f07ca86c</a> ?</div><div><pre style="color:rgb(0,0,0);word-wrap:break-word;white-space:pre-wrap">From 444fb00ff2a9d1f40a8c66f48bea1cf3f07ca86c Mon Sep 17 00:00:00 2001
From: jonasf <<a href="mailto:jonas.falkevik@mobilearts.com">jonas.falkevik@mobilearts.com</a>>
Date: Fri, 15 Jun 2018 15:55:38 +0200
Subject: [PATCH] erts realloc optimization same size
optimize the case when realloc is called with same size
---
erts/emulator/beam/erl_binary.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/erts/emulator/beam/erl_binary.h b/erts/emulator/beam/erl_binary.h
index 7dfd0c273a9..9ba6aac1a0d 100644
--- a/erts/emulator/beam/erl_binary.h
+++ b/erts/emulator/beam/erl_binary.h
@@ -419,6 +419,8 @@ erts_bin_realloc_fnf(Binary *bp, Uint size)
ErtsAlcType_t type = (bp->intern.flags & BIN_FLAG_DRV) ? ERTS_ALC_T_DRV_BINARY
: ERTS_ALC_T_BINARY;
ASSERT((bp->intern.flags & BIN_FLAG_MAGIC) == 0);
+ if (bp->orig_size == size)
+ return bp;
if (bsize < size) /* overflow */
return NULL;
nbp = erts_realloc_fnf(type, (void *) bp, bsize);
@@ -436,6 +438,8 @@ erts_bin_realloc(Binary *bp, Uint size)
ErtsAlcType_t type = (bp->intern.flags & BIN_FLAG_DRV) ? ERTS_ALC_T_DRV_BINARY
: ERTS_ALC_T_BINARY;
ASSERT((bp->intern.flags & BIN_FLAG_MAGIC) == 0);
+ if (bp->orig_size == size)
+ return bp;
if (bsize < size) /* overflow */
erts_realloc_enomem(type, bp, size);
nbp = erts_realloc_fnf(type, (void *) bp, bsize);</pre><pre style="color:rgb(0,0,0);word-wrap:break-word;white-space:pre-wrap"><br></pre></div></div></div></div>