[Tarantool-patches] [PATCH 08/20] net.box: remove useless encode optimization

Vladimir Davydov vdavydov at tarantool.org
Fri Jul 23 14:07:18 MSK 2021


luamp_encode copies its argument to the top of Lua stack unless it's
already on the top so netbox_encode_{update,upsert} encode key/tuple and
ops in reverse order to avoid the copy. There's no much point in it,
because copying an argument in Lua stack costs nearly nothing - it's
just a pointer copy. I ran a simple net.box test doing upserts and saw
no difference with and without this optimization. Let's remove it,
because it's easier to rewrite parts of net.box in C without it.
---
 src/box/lua/net_box.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c
index ed1df4a189d2..8952efb7bb39 100644
--- a/src/box/lua/net_box.c
+++ b/src/box/lua/net_box.c
@@ -366,15 +366,13 @@ netbox_encode_update(lua_State *L)
 	mpstream_encode_uint(&stream, IPROTO_INDEX_BASE);
 	mpstream_encode_uint(&stream, 1);
 
-	/* encode in reverse order for speedup - see luamp_encode() code */
+	/* encode key */
+	mpstream_encode_uint(&stream, IPROTO_KEY);
+	luamp_convert_key(L, cfg, &stream, 5);
+
 	/* encode ops */
 	mpstream_encode_uint(&stream, IPROTO_TUPLE);
 	luamp_encode_tuple(L, cfg, &stream, 6);
-	lua_pop(L, 1); /* ops */
-
-	/* encode key */
-	mpstream_encode_uint(&stream, IPROTO_KEY);
-	luamp_convert_key(L, cfg, &stream, 5);
 
 	netbox_encode_request(&stream, svp);
 	return 0;
@@ -402,16 +400,14 @@ netbox_encode_upsert(lua_State *L)
 	mpstream_encode_uint(&stream, IPROTO_INDEX_BASE);
 	mpstream_encode_uint(&stream, 1);
 
-	/* encode in reverse order for speedup - see luamp_encode() code */
-	/* encode ops */
-	mpstream_encode_uint(&stream, IPROTO_OPS);
-	luamp_encode_tuple(L, cfg, &stream, 5);
-	lua_pop(L, 1); /* ops */
-
 	/* encode tuple */
 	mpstream_encode_uint(&stream, IPROTO_TUPLE);
 	luamp_encode_tuple(L, cfg, &stream, 4);
 
+	/* encode ops */
+	mpstream_encode_uint(&stream, IPROTO_OPS);
+	luamp_encode_tuple(L, cfg, &stream, 5);
+
 	netbox_encode_request(&stream, svp);
 	return 0;
 }
-- 
2.25.1



More information about the Tarantool-patches mailing list