From 4eefce356d50040e3e001ce2660a71b78d86fba5 Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Sun, 26 Mar 2017 18:22:10 +0200 Subject: [PATCH] Optimize UUID string decoding I realized, that 30% of the request time in our app is spent by hydrating the uuid (We are using Doctrine and in this specific request I was accidentally hydrating few thousands entities). Luckily, I remembered the #160 and tried to do similar optimization for uuid decoding. It resulted in 10-20% performance improvement. --- src/Codec/StringCodec.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Codec/StringCodec.php b/src/Codec/StringCodec.php index 48d8c32..4618196 100644 --- a/src/Codec/StringCodec.php +++ b/src/Codec/StringCodec.php @@ -156,12 +156,12 @@ class StringCodec implements CodecInterface protected function getFields(array $components) { return array( - 'time_low' => sprintf('%08s', $components[0]), - 'time_mid' => sprintf('%04s', $components[1]), - 'time_hi_and_version' => sprintf('%04s', $components[2]), - 'clock_seq_hi_and_reserved' => sprintf('%02s', substr($components[3], 0, 2)), - 'clock_seq_low' => sprintf('%02s', substr($components[3], 2)), - 'node' => sprintf('%012s', $components[4]) + 'time_low' => str_pad($components[0], 8, '0', STR_PAD_LEFT), + 'time_mid' => str_pad($components[1], 4, '0', STR_PAD_LEFT), + 'time_hi_and_version' => str_pad($components[2], 4, '0', STR_PAD_LEFT), + 'clock_seq_hi_and_reserved' => str_pad(substr($components[3], 0, 2), 2, '0', STR_PAD_LEFT), + 'clock_seq_low' => str_pad(substr($components[3], 2), 2, '0', STR_PAD_LEFT), + 'node' => str_pad($components[4], 12, '0', STR_PAD_LEFT) ); } }