[erlang-questions] UDP receive performance

Jonas Falkevik jonas.falkevik@REDACTED
Fri Jun 15 22:53:57 CEST 2018


On Fri, Jun 15, 2018 at 12:07 PM, Jonas Falkevik <
jonas.falkevik@REDACTED> wrote:

> >
> >
> > 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
> >
>
> Something like
https://github.com/falkevik/otp/commit/444fb00ff2a9d1f40a8c66f48bea1cf3f07ca86c
?

>From 444fb00ff2a9d1f40a8c66f48bea1cf3f07ca86c Mon Sep 17 00:00:00 2001
From: jonasf <jonas.falkevik@REDACTED>
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);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180615/6861c954/attachment.htm>


More information about the erlang-questions mailing list