util.serialization: Cache default serialization instance (fixes #1389) 0.11
authorKim Alvefur <zash@zash.se>
Mon, 08 Jul 2019 02:46:27 +0200
branch0.11
changeset 10064 7a36b7ac309b
parent 10063 c8c3f2eba898
child 10065 5c71693c8345
child 10096 4b3c129e96f2
util.serialization: Cache default serialization instance (fixes #1389) Most serialization uses still use the default serialize() and thus duplicate much of the setup, which negates some of the performance improvements of the rewrite.
util/serialization.lua
--- a/util/serialization.lua	Mon Jul 08 01:17:34 2019 +0200
+++ b/util/serialization.lua	Mon Jul 08 02:46:27 2019 +0200
@@ -272,10 +272,15 @@
 	return ret;
 end
 
+local default = new();
 return {
 	new = new;
 	serialize = function (x, opt)
-		return new(opt)(x);
+		if opt == nil then
+			return default(x);
+		else
+			return new(opt)(x);
+		end
 	end;
 	deserialize = deserialize;
 };