Skip to content

Conversation

@filipecosta90
Copy link
Contributor

@filipecosta90 filipecosta90 commented Apr 14, 2022

Fixes #8826 8826

As pointed out on #8826 all commands / use cases that heavily rely on double to a string representation conversion, (e.g. meaning take a double-precision floating-point number like 1.5 and return a string like "1.5" ), could benefit from a performance boost by swapping snprintf(buf,len,"%.17g",value) by the equivalent fpconv_dtoa or any other algorithm that ensures 100% coverage of conversion.

This is a well-studied topic and Projects like MongoDB. RedPanda, PyTorch leverage libraries ( fmtlib ) that use the optimized double to string conversion underneath.

The positive impact can be substantial. This PR uses the grisu2 approach ( grisu explained on https://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf section 5 ).

test suite changes

Despite being compatible, in some cases it produces a different result from printf, and some tests had to be adjusted.
one case is that %.17g (which means %e or %f which ever is shorter), chose to use 5000000000 instead of 5e+9, which sounds like a bug?
In other cases, we changed TCL to compare numbers instead of strings to ignore minor rounding issues (expr 0.8 == 0.79999999999999999)

Impact on Sorted Sets

READS

If we look at ZRANGE WITHSCORES command impact we saw 23% improvement on the achievable ops/sec on replies with 10 elements, 50% on replies with 100 elements and 68% on replies with 1000 elements. For more details check the section below.


Testing positive impact on ZSET commands (with double scores) :

This can be easily tested using https://github.com/redis/redis-benchmarks-specification ( install details on repo )

redis-benchmarks-spec-client-runner --db_server_host <IP> --test memtier_benchmark-1key-zset-100-elements-zrange-all-elements.yml,memtier_benchmark-1key-zset-10-elements-zrange-all-elements.yml,memtier_benchmark-1key-zset-1K-elements-zrange-all-elements.yml --flushall_on_every_test_start --flushall_on_every_test_end

If you want to manually replicate the results, then follow the next steps:

To populate the data

# 10 elements zset

redis-cli "ZADD" "zset:10" "0.306275" "lysbgqqfqw" "0.486004" "mtccjerdon" "0.941626" "jekkafodvk" "0.602656" "nmgxcctxpn" "0.630771" "vyqqkuszzh" "0.406379" "pytrnqdhvs" "0.521814" "oguwnmniig" "0.182854" "gekntrykfh" "0.657658" "nhfnbxqgol" "0.218066" "cgoeihlnei"

# 100 elements zset

redis-cli "ZADD" "zset:100" "0.306275" "lysbgqqfqw" "0.486004" "mtccjerdon" "0.941626" "jekkafodvk" "0.602656" "nmgxcctxpn" "0.630771" "vyqqkuszzh" "0.406379" "pytrnqdhvs" "0.521814" "oguwnmniig" "0.182854" "gekntrykfh" "0.657658" "nhfnbxqgol" "0.218066" "cgoeihlnei" "0.366328" "kgqrovsxce" "0.520723" "imyizmhzjk" "0.426630" "urvgxwbiiz" "0.878001" "onzjrteqmu" "0.126097" "alqlzsvuuz" "0.562698" "lgrkndhekf" "0.357487" "tcjvjofxtd" "0.395563" "ouuybhtvyb" "0.745796" "owbbdezgxn" "0.165356" "ksqpdywgdd" "0.757214" "qrosceblyo" "0.346153" "agsdggdghc" "0.297342" "gfdqdrondm" "0.668749" "oapbvnisyq" "0.281552" "htvbwmfyic" "0.013874" "vyoomgwuzv" "0.052023" "pcxdhdjwnf" "0.648518" "ibhohmfxzt" "0.967245" "erxulvebrj" "0.971791" "qwxrsgafzy" "0.154577" "whmotknaff" "0.404082" "ueyrvldzwl" "0.324634" "nsxaigrnje" "0.342459" "xsepfhdizi" "0.988925" "exvhmqxvvp" "0.345154" "owtkxlzaci" "0.728413" "ypfeltycpy" "0.406783" "qbiwbqiubb" "0.714527" "wqiwdbncmt" "0.760975" "dapacykoah" "0.212614" "hhjclfbbka" "0.445330" "ujrxcmpvsq" "0.576866" "lbtpbknelm" "0.764225" "wvcnqbvlnf" "0.281427" "mibvtmqxcy" "0.596978" "aovfsvbwjg" "0.650632" "qbyhorvill" "0.948063" "ypekeuutef" "0.028779" "xamjodnbpf" "0.678338" "hhniikmtsx" "0.757806" "sahqeskveq" "0.671949" "bqntlsaqjb" "0.190314" "luemuetmia" "0.219219" "zwnitejtpg" "0.212301" "ncjfckgkcl" "0.730613" "qjyeqcfhjj" "0.657992" "wkbasfyzqz" "0.556851" "ccagtnjilc" "0.543822" "pqyurbvifk" "0.101854" "djetcyfxuc" "0.878471" "vpmpffdoqz" "0.696931" "hlpdstpvzw" "0.662898" "imdqxmkzdj" "0.887214" "eouliovvra" "0.193298" "gxephxbdru" "0.978115" "dlsjwmqzhx" "0.743150" "uapsgmizgh" "0.181609" "gorgpnnqwr" "0.638726" "rojeolnopp" "0.561627" "mbxohpancs" "0.223001" "upodnpqenn" "0.957952" "dlbqcynhrn" "0.586659" "ichqzmiyot" "0.813623" "ulbrotlhze" "0.111318" "licotqplim" "0.525834" "mxwgdcutnb" "0.405858" "vpbkvwgxsf" "0.129768" "ijsmoyesvd" "0.591274" "mbgehjiauu" "0.718370" "vymjzlzqcn" "0.189343" "rjkknoigmu" "0.566307" "jxoxtnzujs" "0.563082" "eqlgkwosie" "0.040883" "ljcgdooafo" "0.326765" "cwaveajmcz" "0.423381" "ssjqrsluod" "0.865798" "fhuvzpxjbc" "0.784445" "perfwnpvkl" "0.659790" "mjjuylgssm" "0.918901" "vxcbagyymm" "0.282908" "nxcdcaqgit" "0.030110" "ewomnmugfa" "0.164237" "rkaznetutk" "0.281729" "rqvryfvlie" "0.877790" "holjcdpijr" "0.878293" "pquewclxuy" "0.674968" "ocrcszcznp" "0.520069" "xczfmrxrja" "0.314841" "nxzsnkmxvi" "0.719988" "hhjchwjlmc"

# zadd 1000 elements

"ZADD" "zset:1000" "0.645108" "iehxaaneev" "0.793870" "icatrrbcjs" "0.558445" "aieekmivcb" "0.712596" "xwtwtwmbgu" "0.138467" "ctnaggdbru" "0.319593" "nouncgkoik" "0.193744" "naggqdxcjm" "0.238679" "qjrhtqgwjc" "0.308197" "ihealvwnxb" "0.903443" "hggqmlgwha" "0.210797" "pjdundsxrd" "0.706360" "zcffhzusrl" "0.392186" "hmcpcrjumm" "0.392543" "iiissmznfe" "0.024854" "caaqjozcqh" "0.169284" "ooeswhfdnj" "0.545674" "txgjxzovte" "0.943467" "xpcpytommm" "0.130763" "icqjxcermo" "0.167315" "vqtixjkcbb" "0.629596" "wwfbpjatrp" "0.413113" "vtaiyncmyg" "0.457128" "aslibwggrp" "0.105554" "bpvbnmpekh" "0.771857" "gaotvjctjh" "0.306570" "diwmfuckel" "0.939014" "dgcesswkvc" "0.905870" "cflarkquuv" "0.063393" "lqqivzlppd" "0.582370" "iwqanwtvcd" "0.031539" "nvonwipkta" "0.720765" "rcwbzvwbva" "0.315533" "sbrjnwxdip" "0.688803" "kuiumwomxi" "0.890704" "qgobfhgspy" "0.334490" "wmvhvwnowp" "0.673452" "uewpgskfpu" "0.819089" "cvnlzjdfgf" "0.846270" "mhbfsuaovv" "0.652710" "anmcogawkg" "0.778304" "xsueeljljp" "0.771838" "padscbypdo" "0.177771" "tjnjhejnju" "0.793709" "dxdngrmypg" "0.799628" "itmekixthv" "0.017343" "giubyhvaav" "0.004991" "bbfvuialin" "0.580003" "tctgzmjads" "0.405932" "mvfnirshbd" "0.851340" "asbtvfzien" "0.226860" "vqashxkrik" "0.391362" "gazojexans" "0.287772" "wybmlpqblt" "0.191989" "mobwpcyxuk" "0.224179" "sjbaedopjb" "0.202665" "axhoxkubdv" "0.968856" "rqiyxwpuyv" "0.483072" "jpphbjtbrh" "0.991346" "mvmsikqfxu" "0.350243" "ltkauvxggz" "0.588627" "rwllkdzxrj" "0.039496" "hhwvslfxmf" "0.700638" "cgpvvnbvlk" "0.313291" "fgcehqgsso" "0.343576" "oownjpxrov" "0.192722" "umwunfzsvo" "0.273418" "jzceexkqam" "0.968219" "arqqmfmmbz" "0.394788" "plqbwsiuzw" "0.378863" "rhnkzlsjtk" "0.605956" "eioxaswdee" "0.438622" "rspghuhpbp" "0.356931" "zexblqeora" "0.009694" "stttkrbfqs" "0.620955" "rmqxtqcxua" "0.713440" "emdwpvauyc" "0.999344" "olezxlliej" "0.361739" "imnjbkmsls" "0.308247" "thqttakyzy" "0.424859" "jjlefkekuw" "0.036802" "qgasrnjrld" "0.160174" "whdftyqojv" "0.725586" "snepgcispg" "0.004061" "ipubipttcb" "0.702881" "ocesqguvym" "0.206341" "qwxzqlqter" "0.831086" "xmknbbmdbf" "0.353833" "spoqshzjoi" "0.029532" "slskrnekbc" "0.389068" "gybxnvwchp" "0.520218" "uvlswctlhx" "0.872011" "ujybghjfnf" "0.299529" "lgqazzajpx" "0.153536" "yhlalzusch" "0.611873" "jeazfmhrcb" "0.795973" "vealtjlqyc" "0.284121" "ejzwnidqwr" "0.429848" "nifzrybfuh" "0.133500" "qlorevyltp" "0.870113" "wvdmobfisx" "0.240635" "aqyfvxyjqr" "0.903983" "zybosgbtxt" "0.305875" "bvvoibkfrt" "0.132423" "iziwqojsoq" "0.041522" "qpffifpdiz" "0.085682" "ocoflktdhp" "0.159059" "ncabqesziv" "0.650525" "zuccleayil" "0.354068" "pfvfxrrfhl" "0.546089" "rdipvyeqoi" "0.452595" "yrsizkbbwz" "0.723931" "iwuuxdactm" "0.595940" "mbewprqunw" "0.933906" "ajdkqflpen" "0.696150" "wmyphdckda" "0.841744" "lxoaezrdxs" "0.461889" "jqqogagqni" "0.141414" "yhdgqenmwv" "0.347382" "wrrgxxkxkc" "0.398727" "omwbgglqsp" "0.443000" "ymqxhmnidz" "0.765094" "nqwjivcosg" "0.986056" "tctrsxgnrc" "0.576107" "ndwiompimr" "0.349571" "cmhkstsjok" "0.734824" "jfbgmhtjke" "0.929214" "gdlztbhpeq" "0.102103" "kmifjielrw" "0.796464" "khkkfmzkow" "0.044303" "akzsgaeqon" "0.349244" "ozpyyaznsh" "0.282090" "dvgqwzignk" "0.124180" "lawrpikwsk" "0.145508" "qnqzibcmip" "0.014177" "jlghqxtvok" "0.271586" "orqqevpmca" "0.941327" "yrvmdhnnfc" "0.964838" "ajkgxmtamu" "0.681722" "mcbuftndrr" "0.524113" "caxgjftjyj" "0.432128" "bzwxqcpftf" "0.167489" "krfosgrmjb" "0.309948" "ilkuddrdvh" "0.910226" "byrkeibrfb" "0.382510" "bpnfopinub" "0.152318" "gbeizdzdyb" "0.570025" "vgfgbsbnwy" "0.290087" "zbfeyptemz" "0.376504" "wcouaiatsu" "0.071776" "omeatkwwtc" "0.029506" "cbjovvgqqy" "0.484980" "ofykgotycd" "0.043870" "bnxtlmiwup" "0.751689" "uqvzpcvugl" "0.419781" "rwfykeeqgx" "0.087991" "nubsytpfao" "0.808363" "xeyxlxiqch" "0.187833" "rrrfhnclbv" "0.864568" "mnsaklzgob" "0.725490" "zujobawsct" "0.204763" "pcuaesomdc" "0.223025" "lftmqoxhfc" "0.506344" "fgygwdazbm" "0.261202" "maxylirjgh" "0.410370" "jgaieawkcu" "0.260167" "ffrviosqzo" "0.250480" "fiafoggekm" "0.563103" "wksgvbkbyw" "0.974324" "nmguhcygct" "0.259207" "bekchebgys" "0.783447" "hmnaoeeasz" "0.764739" "zknlteeaxq" "0.828842" "qzxxwlfeki" "0.464344" "knycrcrsbm" "0.984059" "izizuzzjuv" "0.384700" "blujwnyluy" "0.930637" "zrwgpknaop" "0.656346" "fffreqppjj" "0.051069" "alfftdxaxc" "0.320961" "ywmqoaztmy" "0.279848" "lbjarnpxhh" "0.294326" "ecsburyjhh" "0.806331" "jetamrlglx" "0.208517" "ruxsmttpak" "0.257535" "hxbmykkugi" "0.821400" "jzstgleeby" "0.546144" "bovkdabcdo" "0.226768" "jhkdwtqvwl" "0.398483" "iqbyikqjmx" "0.125020" "snomfrutha" "0.264133" "eiziligjfr" "0.043614" "bqoabrqwwj" "0.411120" "utymwhxigo" "0.850358" "bstezdkmig" "0.485876" "csjfbpjyzq" "0.528742" "yzrdbalexf" "0.110554" "uidvmrqyjd" "0.751337" "yjhypaonqq" "0.074346" "gktcjcfxbb" "0.020820" "lqxpnplleo" "0.234692" "vfcpevtekf" "0.157122" "xglrugpjkt" "0.174485" "fidsuuizcf" "0.939223" "gdqgmwxkmt" "0.436623" "ghepftfjgk" "0.071851" "mjwrbndexu" "0.847464" "shlwywnxpk" "0.646937" "wlogkzxkpo" "0.532516" "pwgjoppmgc" "0.592209" "ossjrvqmaa" "0.598701" "rnvhfxbuoi" "0.443002" "lydebbpmfb" "0.279549" "sdnkjddyut" "0.877963" "zewylkylsy" "0.080681" "rnfodijavx" "0.696470" "ukdnaklmcp" "0.102279" "tcpwkimype" "0.881048" "bgcoyoduda" "0.415925" "gpodilvrnm" "0.848481" "srkvjhetmj" "0.040637" "ltgidziwzm" "0.244640" "tnratexlre" "0.075067" "tfonhwnuxj" "0.034629" "rpyroriegs" "0.887395" "rjrtvpntke" "0.685654" "vvmkjgajwa" "0.400525" "nywteueaig" "0.435228" "vklwhyzqhk" "0.060039" "afzlyodwiz" "0.510563" "ropuqidkxv" "0.048751" "roczxpuisd" "0.269116" "mhxojehvxx" "0.988874" "dqqfcdugde" "0.240165" "qtpcwuafar" "0.750459" "uvqtefqdhk" "0.828087" "tstbluhyhj" "0.861661" "kxggjpatkd" "0.351980" "wgtjxahmef" "0.440586" "tdceweesxh" "0.897607" "qzlfnntjar" "0.564519" "ljklggibcy" "0.372248" "nwnyjkugcf" "0.098880" "qmhyoyctod" "0.545321" "bwsdzrxzse" "0.996184" "kmcwshsbye" "0.819622" "ifhkjgmxrd" "0.034752" "lnuuootxmp" "0.243929" "yfdsmhtria" "0.317712" "pupmdjgyed" "0.706819" "aryiyaltqw" "0.755626" "eyhgspybnr" "0.066966" "babfjxxabw" "0.681568" "qhhhipzncq" "0.289070" "rwhzzytdsq" "0.040067" "rbdabbmnrf" "0.325428" "sfuvzzxbxq" "0.377881" "fgjnsosfrp" "0.737437" "llimzyabsp" "0.035594" "ufdxqlonpg" "0.343033" "mjlpvuoghe" "0.189450" "dyzedskzkq" "0.671180" "dbcxnsiacw" "0.679152" "fsuovvpgng" "0.919742" "tvlckdoyfe" "0.191694" "pkehotsmka" "0.219460" "nryvfijxhj" "0.188159" "yqvkykgjbe" "0.564495" "jlgepeyhpc" "0.238642" "nwywtydqew" "0.751883" "cakvxrdpmj" "0.894821" "eaetplspga" "0.630431" "lrhrkuyzry" "0.358602" "ksppwhhqzj" "0.489667" "skkawcmqqt" "0.778531" "mkrrypcfzy" "0.101774" "tkgihmsrha" "0.268255" "oqdlpaubsc" "0.577108" "mdcwoblmkl" "0.260332" "rjrptuhkav" "0.516929" "wvsnfinuil" "0.941773" "aexxjlgwuo" "0.196086" "kohpozxkhl" "0.137598" "qxxinxaqxn" "0.378124" "pltsnzqvpi" "0.579231" "mcojdazpfq" "0.240701" "xkvgnzjgrm" "0.898586" "fzzcioobeb" "0.264136" "tqblforkpa" "0.448451" "skbzfbeziu" "0.051773" "vyiqkfoics" "0.536133" "lxzdcbveuy" "0.502064" "hskkmrluuf" "0.698222" "ltomuspfzc" "0.590610" "fmpdixcckx" "0.057498" "ukprrucywq" "0.660543" "vldwfdnicm" "0.826104" "fzatoyblsr" "0.754438" "wbouqpojzl" "0.117783" "pmaagvqldo" "0.533611" "wxjdgbugeu" "0.025197" "nlqtadqinl" "0.760125" "jgcqryhsvk" "0.551085" "uboipezuni" "0.203084" "tmkoxwdgpx" "0.415950" "xgfzndhodu" "0.271285" "vuqlqdpfdn" "0.385063" "zorzyqtjtr" "0.537420" "uedehyieof" "0.972732" "jphvxuqipp" "0.733064" "faxedqgskm" "0.342786" "cdghgcsoth" "0.903818" "qwowxqzrkz" "0.653952" "roqzbzpbbt" "0.768345" "sxcihybfci" "0.892237" "pbxrbaxnor" "0.764531" "geizujxrkg" "0.620438" "beqsnrixhl" "0.521196" "llamjvxyqo" "0.699100" "yzcspfvcot" "0.459957" "ubghghklvj" "0.297416" "giswndixdf" "0.086339" "kgopxvsdah" "0.000782" "tocawprsxz" "0.426201" "ctusqixohm" "0.339036" "hklchdenoe" "0.276883" "btgeubdzbb" "0.860669" "cjcrpmggtu" "0.147353" "ngcxqjjpdm" "0.875443" "vorgqhmaoq" "0.923510" "bgcnzgcmza" "0.087182" "pyjpxqnavq" "0.634058" "tdmjyuitvv" "0.963838" "igwekdegcw" "0.235680" "spogjykkfs" "0.675610" "vlcnbfqvox" "0.661566" "tzhjrlfvfp" "0.317132" "ebhhhgabjd" "0.118838" "evuxmkrrfl" "0.246357" "pxzkuasjek" "0.450004" "hnnfmyurhx" "0.623882" "yzutuazhmh" "0.331435" "eovsizpcjp" "0.218206" "dfemamyevk" "0.935043" "evjrybtwww" "0.820919" "audguegpmo" "0.966038" "nwybjbhgep" "0.748183" "nrencopzqn" "0.287079" "hyikggurti" "0.375950" "xwxwosqkhm" "0.388941" "kcbotffyca" "0.676492" "xhspgwheck" "0.782514" "rkwlgzhvvy" "0.628528" "tumnalubch" "0.672107" "dhfundvlpn" "0.661732" "qsxfnsicrx" "0.975140" "gamcdtywne" "0.608014" "asidljmwgb" "0.897256" "gygftrsdbm" "0.349942" "ybckvbeoib" "0.932954" "anznywecwk" "0.726428" "cgmivhyskk" "0.843359" "xkiuuciwrn" "0.023708" "lyhqvxolfw" "0.822799" "eafrzhdhhq" "0.530864" "dbtbtvkqss" "0.848648" "hvxefqtmqu" "0.866428" "eraxdyjftw" "0.446144" "eyrbqexkff" "0.048181" "dxtzxeguoi" "0.683328" "owjfgjqqjc" "0.489625" "pisgqibyae" "0.970240" "nsdvirehqh" "0.583183" "wgtrwefdsw" "0.174619" "mamtueyrqn" "0.222798" "wiqhmhkiel" "0.704784" "cnngbbpowp" "0.837632" "curhymvwsx" "0.256654" "uttazeawix" "0.701426" "farwqgfyjf" "0.463106" "mivctgaajt" "0.534385" "qchpfcigwa" "0.538479" "lspvrnxnjo" "0.571538" "bzjzucrypq" "0.599488" "pyrpwxalpc" "0.924799" "rncdgqxqfq" "0.315947" "nenhiiibwx" "0.909998" "arqfxfqkzh" "0.405248" "fpdflprzvn" "0.674952" "cuuytorpnp" "0.955493" "lfojnetxdc" "0.692204" "uqbpcvkipa" "0.991647" "pribqncfuf" "0.597850" "xbvbujurqw" "0.498266" "expefhkisx" "0.231363" "wwowdvybjj" "0.357729" "qsoiwsugdv" "0.401551" "ntmgbzaivy" "0.230953" "kjblkrvknt" "0.707000" "xkaailrpns" "0.246097" "muocqqypmt" "0.720597" "dspznsgszk" "0.147380" "gkneclxnnt" "0.753306" "higdkhodzy" "0.003853" "csqcfxyzsy" "0.782493" "iyeiercbxr" "0.732835" "hjekcxfyds" "0.644764" "ahjawbsqcw" "0.038385" "kapxglqccs" "0.229066" "ygbfgfefac" "0.791507" "qpzkuxsipr" "0.991541" "kmqlwfbsex" "0.698087" "vwayaqmtid" "0.972772" "ghtoyhrfxh" "0.890508" "gcsswbksnc" "0.949597" "snpuvnebpy" "0.107435" "mugdxqnjxj" "0.618836" "vkqalcokst" "0.433195" "ltghdkluqq" "0.448407" "mumhqarhgg" "0.135863" "gbjzsedhag" "0.564412" "hvfprkjlbc" "0.228627" "jqgtbgbybq" "0.826784" "ydqppngxvh" "0.990663" "iamjlqlznh" "0.361827" "zzenkvuesw" "0.922425" "rmdayyptch" "0.150657" "ripecixnpr" "0.174850" "pkgpjwyfbh" "0.949969" "ortxlvmdoc" "0.857772" "rcaatkjyur" "0.649739" "qqfnugftmr" "0.332970" "bsavjyaksg" "0.801014" "pudgkcbwdx" "0.499720" "ynnhyctikq" "0.782441" "ekjgqnjxyl" "0.495010" "kbnjiilaqd" "0.186830" "cvmicoarvv" "0.439088" "iibgagtkpg" "0.715350" "jznackjcrd" "0.289687" "symbgeyple" "0.333963" "xlmvatfsly" "0.958199" "njmufqrykx" "0.541363" "nbizrabfuo" "0.933496" "amuwlfaxwv" "0.714080" "ahfktrqmgh" "0.100087" "kdodndexvr" "0.149844" "isqymcuffe" "0.706632" "yzmodbpsnb" "0.847058" "jlpobgvouj" "0.951551" "eqiukbyscu" "0.068236" "mqqrgbacfa" "0.490453" "mmqblvrscy" "0.235491" "fiugzrozky" "0.377347" "nvkfnfzoki" "0.127271" "vjihaakiof" "0.795512" "apyzwvajot" "0.348210" "lxsinouutc" "0.567777" "ystnkbogee" "0.477872" "oeawjlqnyg" "0.623260" "hyanpicfan" "0.664609" "gtqrsktbaa" "0.320234" "fffylsswky" "0.096201" "zdmgjjyukl" "0.421767" "ffcqkkzllx" "0.421724" "ogyvxbgcwi" "0.195373" "dtkfydidli" "0.127873" "jccorylnjg" "0.049319" "myzjxvtvjh" "0.808586" "dtuhvpszzt" "0.320150" "kamgfgbxel" "0.370480" "nraylduhut" "0.265837" "abinkgshoi" "0.975716" "ghqwxaqlef" "0.502953" "ftnbjymlll" "0.310925" "pzrchtwaaw" "0.567703" "wdqygrxkya" "0.728237" "snunzlgfkd" "0.896651" "nkyuframnm" "0.867424" "rxvhmzvbcv" "0.063563" "rrzcqyzdzf" "0.629553" "weqhfkosif" "0.462773" "ctgwmawlgl" "0.718046" "kpzmuwqbnt" "0.906977" "klaeknlbrm" "0.264978" "cejkfhuykf" "0.619446" "jhibapuhga" "0.061965" "wemmvswznk" "0.061592" "vdaebbupfe" "0.689222" "cglxptkcsz" "0.174769" "quemrlmwod" "0.898675" "ydigxptqbl" "0.948273" "gjutzwoxlf" "0.075856" "vefgwelnfo" "0.746864" "dcepfcdddn" "0.965491" "qkyfpamste" "0.633385" "gbkqhfumyu" "0.737572" "iwapedwyle" "0.754054" "ormdblyhhn" "0.932719" "dtjljhzqcm" "0.767225" "pthacnunjj" "0.649379" "xzswnnldvs" "0.216633" "muhewfzihs" "0.639269" "fuftndsnim" "0.909138" "xyxmlrdbui" "0.508704" "jwvqixjhho" "0.582770" "nfucelqjfe" "0.089356" "glynpmsjcf" "0.838816" "avchkjnlwm" "0.908984" "ylxiwiesps" "0.043408" "sadqcfniau" "0.886747" "qgdgujdvtg" "0.661810" "gfhrrjczsp" "0.907605" "dpauqcpgyi" "0.728562" "ppdxnadmje" "0.330399" "kqzjnkdlxd" "0.082110" "yhejmjwwni" "0.711500" "xsgcuvxzor" "0.866779" "fswhywqxhy" "0.421784" "rtnhivnxtb" "0.497701" "veegnotgmj" "0.518567" "tsmzfswaxo" "0.005142" "ifpfyncdfe" "0.249159" "vpqlxtfkjz" "0.741728" "twmbtaxdro" "0.139049" "cvnnitrrow" "0.070475" "erahoeivfw" "0.488547" "buzhjxsbkm" "0.741781" "nmtmjmhmdl" "0.514985" "fqtktfghcv" "0.866908" "iqzxblqkeo" "0.505662" "qydrgilxxt" "0.773945" "beicnwdryg" "0.668057" "htawohddyn" "0.675705" "jbqibabrmv" "0.784213" "aquymkrswt" "0.845563" "irrovfyshb" "0.239145" "outdlyeqvq" "0.083427" "ofcurtthcs" "0.865472" "xfxlervrgn" "0.410198" "myrrmvflyw" "0.757061" "lywsezpzgf" "0.634949" "jvtalmlkng" "0.435516" "ghwcrdlbjj" "0.228243" "rqkcyxiwhz" "0.337555" "gzekysdunp" "0.252513" "qtewhixedb" "0.767732" "bzfzxzecrs" "0.092367" "whsxmqffqg" "0.920685" "dmxcbvzrxg" "0.238809" "dhzgpwewsx" "0.569625" "flvftlpbjq" "0.681014" "wxswusqpeo" "0.558549" "aeafusfzdn" "0.076310" "gayysuldha" "0.343809" "nvqfyljbef" "0.131309" "ocgjeuljxf" "0.709863" "cnbqnvxmjp" "0.339533" "sotbjzlsvz" "0.818601" "cvbbbdzmie" "0.244589" "dpyjoihqrs" "0.924136" "ivinvxopgz" "0.004308" "zdulfflfqx" "0.113676" "iosqxoobrk" "0.009689" "kjeevccyof" "0.975034" "jigyicdeft" "0.351974" "sqwhsgboef" "0.575486" "bvurseeqmh" "0.701469" "lbxvlwzony" "0.108482" "tqqmmvwact" "0.639351" "keklddczkd" "0.361829" "kbfqdppnfa" "0.342636" "qjwrnhooax" "0.365558" "koujdppfua" "0.866551" "xrvonyieqa" "0.907022" "ccnbldglgl" "0.327711" "egmgddriry" "0.657241" "gfdzgxfdcg" "0.080151" "eirhwkdgfq" "0.599621" "adlryhdbpr" "0.645347" "ezbiwqnabg" "0.216803" "dplonqlliz" "0.436938" "aiqqyusnuv" "0.630922" "fmyleefltp" "0.387614" "mjgvtydjtm" "0.239791" "trwzipsers" "0.686253" "wvlvshnhmx" "0.710512" "nugjvhftma" "0.937218" "yafipxfsip" "0.887614" "shgetgsird" "0.730346" "cblsafugqk" "0.940470" "spdyueanru" "0.203652" "wjhaavxfge" "0.358953" "otadcihtmd" "0.428536" "irlduoinie" "0.203054" "asretszbav" "0.686840" "ekponflaeq" "0.116664" "btxehrokkw" "0.841981" "ctkwlhmgfz" "0.461922" "emfqsjraia" "0.729528" "ncremxgfdb" "0.747886" "dnvwyhyhsn" "0.314724" "gjiwldcfqh" "0.915762" "kluswgtjsf" "0.630900" "uvbtcgtopw" "0.734056" "jjczogqdwz" "0.954115" "iesbitdnjd" "0.922486" "glwrmjpotx" "0.330378" "nmfihtnkel" "0.752510" "tvzacklhdz" "0.826313" "xtwlklqdna" "0.190858" "rfhlttsuqy" "0.286279" "nlxwjmzwln" "0.334573" "vjjozwrovk" "0.266818" "gqybtjuhvq" "0.477130" "phfuspevwk" "0.424753" "vzcclamtun" "0.334857" "gbazuqnmit" "0.926985" "zmmwzkjrjl" "0.273126" "xigznrdgqy" "0.872996" "yufagalzhk" "0.973287" "kngwkkzwts" "0.642007" "fuipidfbjt" "0.640561" "rwzijctxzs" "0.547026" "fhobhpwwkp" "0.976843" "nqxdrqigvf" "0.889949" "zsikdzycyt" "0.955177" "inboyxgoqa" "0.570888" "rsivptwulz" "0.069483" "eqaxrccwjq" "0.476052" "cctlfgicpv" "0.950332" "gdozstnglr" "0.523253" "wovoupawzt" "0.396718" "nunchscyqc" "0.124266" "socoxaegfa" "0.847380" "qbpmtomqpu" "0.157463" "ngwifjdpha" "0.444848" "ztjuqomjck" "0.834028" "hrhiqcarju" "0.242287" "paitaeqrpb" "0.601139" "umoicweaab" "0.937897" "xekxarmwcq" "0.318636" "aejnvyfdst" "0.723443" "mlznoaajqq" "0.216821" "wjibkklezg" "0.418684" "jxiewthqls" "0.261108" "sldzewoxas" "0.123533" "fvemodlpgz" "0.541682" "fgzwwaedjy" "0.327706" "twpiiaedpc" "0.286415" "brrlblrxwa" "0.354345" "fojjpqmbck" "0.162167" "rhzqdtxucc" "0.553529" "fzsoiryhfn" "0.995917" "zavrjnezrf" "0.015279" "uxvibjduto" "0.179399" "puvgjfjyaf" "0.592098" "jybzltmwrs" "0.786701" "xftfzsoiwc" "0.632713" "kkrxiaiife" "0.023264" "nnfxoqebys" "0.639560" "wrqnytptzm" "0.931933" "powzkcrtvv" "0.102203" "gefoharnza" "0.893614" "viwarrumob" "0.548257" "pkcqdokojd" "0.804829" "kzuywkxlku" "0.252774" "iijjcabgak" "0.105055" "nxllkzroin" "0.261153" "uesalivsis" "0.153373" "aqlapmghln" "0.538430" "pfaytznuaa" "0.706254" "ucxeoqcssr" "0.506384" "tivnqailcl" "0.550096" "dtgjnddwch" "0.228131" "suahxaebee" "0.693047" "ubzgvzputq" "0.255977" "tqjpijliii" "0.320788" "mxapzqqqsw" "0.392916" "qvpuudyuks" "0.807373" "kprzbyngsw" "0.579009" "dflxukffgl" "0.639254" "xqvjnlpssl" "0.509891" "wvrlxfoxff" "0.079358" "tqpqihwjtl" "0.174471" "vxrtzngznb" "0.354177" "nahweurftw" "0.735534" "nehqnkqnld" "0.760483" "yfvwesgulw" "0.392384" "zejhycldyy" "0.545858" "cbtpbbfrdd" "0.509818" "oglqutqfcx" "0.171142" "jhctncrzlw" "0.366168" "wqsqzzbqhm" "0.547857" "mkbkflixkr" "0.503947" "nbkaxrojqq" "0.081083" "erqgyscser" "0.370359" "owovlhorvw" "0.309822" "rofnkytnhm" "0.231350" "yajpmxmuwz" "0.394314" "gviypfayfm" "0.784763" "ulnnuwyptq" "0.089208" "ddpgrvwowd" "0.572023" "bweysooxiv" "0.646567" "pnnzqcutoq" "0.839930" "tyephutkmb" "0.264179" "nszbrpweoz" "0.128647" "gehuriygwq" "0.659204" "vpehhmoxva" "0.491950" "dpkiubfzbx" "0.384848" "wgtmckqknh" "0.188043" "xeurpmfdmo" "0.418849" "nbwksmwxpx" "0.605004" "plbxaamppj" "0.276890" "nojnedgabk" "0.833175" "ygrpkpstxq" "0.297792" "etsngvbrff" "0.952694" "qzcrpbvatq" "0.474358" "qbhdjhoohc" "0.067502" "btcvhacldb" "0.014993" "osncqcuest" "0.409761" "uzktwqcdeb" "0.335957" "jttqzbazgz" "0.615791" "qmxxfyuodo" "0.802366" "zuibhuihtz" "0.431484" "ctqxoyxbwc" "0.405363" "azkdbpnshy" "0.590182" "qwozutlufu" "0.916406" "yqmzmmzwpd" "0.493531" "yivxcecwlp" "0.436352" "lzzptujbjp" "0.743434" "ewoqykjbkc" "0.132159" "zxlbhyeckf" "0.302988" "nswjopvtqv" "0.543728" "gkmwutvars" "0.228101" "mupcilqfjg" "0.585761" "skstqdgbos" "0.306041" "kjqeujfkoh" "0.441690" "pvwvdaorrl" "0.920910" "pmytvtksfi" "0.666617" "dniplpxfof" "0.512864" "twuvkpjzzw" "0.600784" "aufhfrhccf" "0.106240" "ljinllovsw" "0.889183" "ywgeotcect" "0.010523" "ltvfnuuwil" "0.081719" "nnnxouavyp" "0.369352" "tglieutcis" "0.790975" "wabroeeoop" "0.431765" "vsvhjrymqc" "0.033449" "jhdcicttmm" "0.334186" "dlhjfafskj" "0.311725" "ffksbrtbfq" "0.735770" "lcdchjadll" "0.402876" "ijdgnlzprg" "0.013454" "znartcywze" "0.320563" "agswwrfabr" "0.859299" "euleuicawb" "0.237979" "aoqlctikzg" "0.084421" "idmjjbjvni" "0.540346" "fkdmuxraqf" "0.827762" "vyewicgjio" "0.264901" "rzanpefsfy" "0.249106" "pubqtzzzko" "0.641931" "btakuczlec" "0.028675" "hfjxrrsszf" "0.112206" "dthtfrqkce" "0.881211" "vnsufnurol" "0.158854" "hmdzsuuyrn" "0.657811" "shckmujxzo" "0.823770" "fmmammvdyj" "0.794376" "fhuptkhkzm" "0.920863" "qquwyuyvvw" "0.237467" "tdggmsxysk" "0.382295" "ysnndkycix" "0.164685" "ftyxhyfokj" "0.924193" "dmbarohbfj" "0.985108" "mallnshtok" "0.932159" "cszvzbrmoy" "0.948943" "stnfirydgi" "0.243979" "bxwvqvndcc" "0.729360" "wtzqqecgfy" "0.827464" "mkngszsxeu" "0.066282" "ncckxlmsvg" "0.832378" "pdjmftsmob" "0.546000" "vqgztpmzhz" "0.880249" "vvmaucizkv" "0.529144" "fnpdsuozxt" "0.599864" "gritvkzfgw" "0.575660" "wtcpliaxmk" "0.095307" "cqfnhujrbj" "0.428143" "osaekeukqx" "0.988758" "nepxmyiuhr" "0.438792" "lfkqrtxocm" "0.337112" "pgdhjrxhga" "0.029529" "wcpbfslakk" "0.817147" "cynhehkcxs" "0.796564" "trzqdcaqdw" "0.292661" "mxydilgynv" "0.296909" "lscjhgztom" "0.658885" "rqurawzebz" "0.291664" "pghbwbtfmk" "0.176822" "ckibsdtfff" "0.884684" "svvdufedug" "0.806829" "fjdjumschq" "0.960759" "ybcdthmgws" "0.806253" "ogtqmpnzie" "0.749828" "yjyffpgoop" "0.313174" "uwiqrvcqvu" "0.978051" "xepfvvcovk" "0.935539" "oxsdmrdbit" "0.949876" "rfxibyjmpg" "0.527448" "gwzqcetcji" "0.136049" "mkxysrkpug" "0.207709" "jjumoixniz" "0.302963" "pypepewjvq" "0.097174" "gcfcbjybkx" "0.982914" "ezgxjiwwig" "0.643767" "kjiqagynco" "0.789879" "urkkyscfti" "0.345265" "tsnawydcru" "0.657757" "sshbuxfljd" "0.849243" "fazsvkljef" "0.122817" "jfqxkxgqhj" "0.874860" "qxbqbfcgjp" "0.019772" "joijmgposs" "0.396742" "qocjpufxio" "0.317664" "xpkwqbfban" "0.417027" "saqilljaid" "0.436455" "qlvgfplbod" "0.689103" "aoydkdfrpe" "0.151562" "dxpepbctea" "0.004086" "jqurtadjro" "0.275095" "szupcnvvij" "0.975388" "nunpqugdit" "0.619831" "cmqraybrlw" "0.021593" "bnatichltp" "0.615263" "zuoqjiciij" "0.516554" "suhwnartid" "0.500129" "bhfmhanvxe" "0.970410" "qckueiqiwh" "0.310292" "hmwfncgzxg" "0.136794" "bhrvnadcdk" "0.537331" "bwjyghaztz" "0.845703" "hwuofuftlr" "0.062857" "xzbqjpzqlm" "0.148334" "rhkpfsuhoq" "0.903658" "ywlqbjqeug" "0.171792" "haxesjafmh" "0.607711" "ouroipthpq" "0.213063" "kdklhpxntt" "0.566853" "mhrvuemywb" "0.066576" "cpjveufsvk" "0.575035" "mszjkgsrio" "0.883155" "rtskokvklv" "0.326063" "kdcvbkrbsj" "0.497748" "pbfijwccjp" "0.096181" "gsvkmnluiz" "0.651896" "brwlqbfoat" "0.698481" "wzxdkpehwf" "0.241647" "hhbceuegvh" "0.335103" "ubwlcefgqb" "0.139593" "vlhtdpqavh" "0.043865" "wghyakzbit" "0.232605" "adfhfatarh" "0.280517" "wevfinjbqk" "0.240397" "scgjdkyetq" "0.661665" "ymwwctfodg" "0.406742" "sotsxznskx" "0.651442" "ckqebhazel" "0.954087" "dwzqowbrsd" "0.118853" "dclualrzqb" "0.859469" "ifiizdeong" "0.715490" "etcsjxoqab" "0.365077" "igehetokzq" "0.303267" "tuajnnqtcq" "0.187568" "mxpzuzrzuo" "0.447848" "oqmuhlruqy" "0.385352" "hvtlkrungk" "0.055211" "dygkzcpakt" "0.403664" "rnlaakgsrf" "0.314530" "yoblelzlkd" "0.082484" "mwmcwqzbld" "0.916300" "mgldvzleyy" "0.169185" "ahcaaodvgi" "0.972997" "erglflfnql" "0.188418" "behdxlfdho" "0.605785" "ikpikupjoi" "0.348162" "ylulwsnjay" "0.512359" "qcsxjrjcfc" "0.376004" "ollacusjzj" "0.312060" "ethxaycsil" "0.912136" "laepwenqmc" "0.629227" "eksvvoxziw" "0.473402" "ulepgommyy" "0.112999" "efhynoxlul" "0.141312" "vhjaphfdpj" "0.501631" "otclvmbilg" "0.622360" "ndltyojjxj" "0.560323" "ehnrizfmfo" "0.856890" "tqkprkoixe" "0.295874" "cvohdragtx" "0.144378" "emfjcnujqn" "0.013908" "bzursuzuei" "0.765880" "qmnxipsiga" "0.655198" "dxnprfawun" "0.921417" "umttshfkpk" "0.269042" "nrbfkysxaf" "0.426194" "xjksnqifds" "0.009747" "qatkvfuttq" "0.222498" "bqqohkuylc" "0.487539" "thmmmlqluk" "0.447940" "gnrmnwaxls" "0.757365" "usykkwszvh" "0.127757" "nnhrgirrtw" "0.114722" "sujbwndgwl" "0.320579" "pkvcbelpos" "0.028885" "fussukqrph" "0.898756" "bgtxhxkhvv" "0.440242" "ywiurvfbpg" "0.195203" "rakustfykw" "0.455870" "txhllnvudv" "0.038326" "smwbxeqbed" "0.636364" "rdsfcdvkqz" "0.602638" "nknlysgviv" "0.703795" "yzviqaobku" "0.517737" "rngtndwjyg" "0.896203" "jqmscuprwq" "0.758854" "bcwncpnibg" "0.497263" "rwrxxrnwtq" "0.810537" "fpmbbgiaao" "0.816854" "mshexjmkmn" "0.132051" "rhzpguhsws" "0.319074" "krxneqolle" "0.336648" "dozecfsvue" "0.607888" "jbzyfznpdn" "0.971581" "tjnbsybxws" "0.261454" "vpzsmbjkvy" "0.581137" "dewdgfrhos" "0.680898" "gcjruttnno" "0.999251" "uzaejrbwue" "0.158681" "jvekvvldai" "0.606900" "imexfccbxk" "0.986671" "exhjfssojj" "0.999539" "hjjxyybxiv" "0.548141" "mjifqzmtsd" "0.838391" "tbqidtevrl" "0.812230" "hjlhurakwh" "0.308053" "ughnpilqqm" "0.047394" "kfselnpkim" "0.852908" "vewfxcxkpf" "0.201866" "usjmfkopln" "0.126260" "yxsnreuepl" "0.246804" "flrsaczxzc" "0.835412" "aadzbodres" "0.293504" "bhwytqsafu" "0.708503" "lpahctqgna" "0.045136" "zwlhpcahwu" "0.601683" "kgirldeylz" "0.556444" "krtsiucvvu" "0.595704" "adlxahxsbq" "0.191964" "alokvrpbih" "0.572409" "mmcunsiwad" "0.551146" "dfdodbelzn" "0.441988" "ejlunxlwxn" "0.419999" "tlnkrncpwi" "0.037276" "jhocasnttw" "0.132050" "qslrwqmixc" "0.767421" "afamsavgsi" "0.697485" "ramoirrdyd" "0.245522" "hplvvuoscb" "0.506283" "dxufcyurjx" "0.614086" "dablvesuho" "0.085394" "ovqohpxjft" "0.343138" "qclkaeciey" "0.148648" "dgodkfjzos" "0.740439" "iobkwbwceu" "0.829028" "ocmtsfpsgh" "0.472991" "ubtiscdgrn" "0.349979" "fsoardckcw" "0.094781" "sstqpivwip" "0.846751" "wzuhzzdezi" "0.746618" "tmyuncyoyd" "0.338101" "ygoiannoht" "0.538581" "zkbqvttlzy" "0.306575" "bwizktcwmb" "0.560909" "dcjlwhfstw" "0.075409" "pheajlhymx" "0.142967" "ysntbzffxq" "0.385727" "rgtondctpo" "0.825053" "uncqdpbhwb" "0.231924" "bdtbaxnuko" "0.138864" "fsthobmdxk" "0.309461" "auwfujaoya" "0.288084" "hertbwuzyw" "0.452947" "azpwrzovza" "0.987974" "yilvzcevlj" "0.374557" "kpfqxroqbs" "0.224445" "dlomhvkoxg" "0.205225" "vjhpmffzxc" "0.863114" "klwqsggtob"

To benchmark (swap keyname for 10 and 100 variants) :

memtier_benchmark --test-time 60 -c 10 -t 8 --pipeline 1 --hide-histogram --command="zrange zset:100 0 1 byscore withscores"

results comparing unstable ( 9ab873d ) vs this PR:

achiavable ops/sec on a standalone scenario

test unstable ( 9ab873d ) this PR (filipecosta90/ac54ab41) % change
ZRANGE 10 elements 96405 118367.83 22.8%
ZRANGE 100 elements 19947 29793.25 49.4%
ZRANGE 1000 elements 3159 5324.53 68.6%

overall client side p50(ms)

test unstable ( 9ab873d ) this PR (filipecosta90/ac54ab41) % change
ZRANGE 10 elements 1.815 1.479 22.7%
ZRANGE 100 elements 10.623 7.007 51.6%
ZRANGE 1000 elements 63.487 37.631 68.7%

Copy link
Contributor

@zuiderkwast zuiderkwast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I didn't read the deps code.


Fast and accurate double to string conversion based on Florian Loitsch's Grisu-algorithm[1].

This port contains a subset of the 'C' version of Fast and accurate double to string conversion based on Florian Loitsch's Grisu-algorithm available at [github.com/night-shift/fpconv](https://github.com/night-shift/fpconv)).
Copy link
Contributor

@zuiderkwast zuiderkwast Apr 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a subset of the files from that repo?

It would be useful to include some info about how to update the lib in the future. If some change is needed, it could be included as a patch file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree. will prepare the initial patch @zuiderkwast

@filipecosta90 filipecosta90 added the action:run-benchmark Triggers the benchmark suite for this Pull Request label Oct 8, 2022
@filipecosta90 filipecosta90 requested a review from oranagra October 8, 2022 13:23
@filipecosta90
Copy link
Contributor Author

@oranagra @sundb and @zuiderkwast I revamped this PR and on my personal laptop ( os:Darwin 21.6.0 arm64 , compier:Apple clang version 14.0.0 (clang-1400.0.29.102) ) redoing the same zrange benchmarks resulted in larger inputs now comparing unstable vs this PR. The improvement is even larger. I've retriggered the "official automation" so lets wait for the grafana data to be populated, but it all points to a good improvement.

To test it I simply ran ( after the pre-poluation described in the top comment ) :

for x in 10 100 1000; do memtier_benchmark --test-time 60 -c 10 -t 8 --pipeline 1 --hide-histogram --command="zrange zset:$x 0 1 byscore withscores" ; done

achievable ops/sec on a standalone scenario

test unstable ( f609a4e ) this PR % change
ZRANGE 10 elements 94830.02 127661 34.6%
ZRANGE 100 elements 17415 30048 72.5%
ZRANGE 1000 elements 2901 9329 221.6%

here's the full output of memtier:

unstable


for x in 10 100 1000; do memtier_benchmark --test-time 60 -c 10 -t 8 --pipeline 1 --hide-histogram --command="zrange zset:$x 0 1 byscore withscores" ; done
Writing results to stdout
[RUN #1] Preparing benchmark client...
[RUN #1] Launching threads now...
[RUN #1 100%,  60 secs]  0 threads:     5689853 ops,   95741 (avg:   94830) ops/sec, 45.29MB/sec (avg: 44.86MB/sec),  0.83 (avg:  0.84) msec latency

8         Threads
10        Connections per thread
60        Seconds


ALL STATS
==================================================================================================
Type         Ops/sec    Avg. Latency     p50 Latency     p99 Latency   p99.9 Latency       KB/sec 
--------------------------------------------------------------------------------------------------
Zranges     94830.02         0.84132         0.83900         1.31900         1.78300     45933.29 
Totals      94830.02         0.84132         0.83900         1.31900         1.78300     45933.29 
Writing results to stdout
[RUN #1] Preparing benchmark client...
[RUN #1] Launching threads now...
[RUN #1 100%,  60 secs]  0 threads:     1027578 ops,   17142 (avg:   17125) ops/sec, 67.93MB/sec (avg: 67.86MB/sec),  4.64 (avg:  4.65) msec latency

8         Threads
10        Connections per thread
60        Seconds


ALL STATS
==================================================================================================
Type         Ops/sec    Avg. Latency     p50 Latency     p99 Latency   p99.9 Latency       KB/sec 
--------------------------------------------------------------------------------------------------
Zranges     17415.86         4.65029         4.67100         5.15100         5.88700     70666.89 
Totals      17415.86         4.65029         4.67100         5.15100         5.88700     70666.89 
Writing results to stdout
[RUN #1] Preparing benchmark client...
[RUN #1] Launching threads now...
[RUN #1 100%,  60 secs]  0 threads:      171286 ops,    1993 (avg:    2853) ops/sec, 77.69MB/sec (avg: 111.24MB/sec), 40.42 (avg: 28.02) msec latency

8         Threads
10        Connections per thread
60        Seconds


ALL STATS
==================================================================================================
Type         Ops/sec    Avg. Latency     p50 Latency     p99 Latency   p99.9 Latency       KB/sec 
--------------------------------------------------------------------------------------------------
Zranges      2901.70        28.01754        27.26300        48.38300        82.94300    115829.84 
Totals       2901.70        28.01754        27.26300        48.38300        82.94300    115829.84 

this PR


for x in 10 100 1000; do memtier_benchmark --test-time 60 -c 10 -t 8 --pipeline 1 --hide-histogram --command="zrange zset:$x 0 1 byscore withscores" ; done
Writing results to stdout
[RUN #1] Preparing benchmark client...
[RUN #1] Launching threads now...
[RUN #1 100%,  60 secs]  0 threads:     7532069 ops,  125730 (avg:  125533) ops/sec, 46.52MB/sec (avg: 46.45MB/sec),  0.63 (avg:  0.63) msec latency

8         Threads
10        Connections per thread
60        Seconds


ALL STATS
==================================================================================================
Type         Ops/sec    Avg. Latency     p50 Latency     p99 Latency   p99.9 Latency       KB/sec 
--------------------------------------------------------------------------------------------------
Zranges    127661.39         0.63489         0.63900         0.98300         1.20700     48371.70 
Totals     127661.39         0.63489         0.63900         0.98300         1.20700     48371.70 
Writing results to stdout
[RUN #1] Preparing benchmark client...
[RUN #1] Launching threads now...
[RUN #1 100%,  60 secs]  0 threads:     1802940 ops,   30094 (avg:   30048) ops/sec, 91.07MB/sec (avg: 90.93MB/sec),  2.64 (avg:  2.64) msec latency

8         Threads
10        Connections per thread
60        Seconds


ALL STATS
==================================================================================================
Type         Ops/sec    Avg. Latency     p50 Latency     p99 Latency   p99.9 Latency       KB/sec 
--------------------------------------------------------------------------------------------------
Zranges     30048.67         2.63966         2.63900         3.10300         3.61500     93109.79 
Totals      30048.67         2.63966         2.63900         3.10300         3.61500     93109.79 
Writing results to stdout
[RUN #1] Preparing benchmark client...
[RUN #1] Launching threads now...
[RUN #1 100%,  60 secs]  0 threads:      569157 ops,    9115 (avg:    9485) ops/sec, 269.50MB/sec (avg: 280.45MB/sec),  8.78 (avg:  8.42) msec latency

8         Threads
10        Connections per thread
60        Seconds


ALL STATS
==================================================================================================
Type         Ops/sec    Avg. Latency     p50 Latency     p99 Latency   p99.9 Latency       KB/sec 
--------------------------------------------------------------------------------------------------
Zranges      9329.70         8.41997         8.44700        10.30300        11.19900    282469.49 
Totals       9329.70         8.41997         8.44700        10.30300        11.19900    282469.49 

@oranagra
Copy link
Member

oranagra commented Oct 8, 2022

@filipecosta90 i see some tests are failing, please look into it.
also, i don't see any correspondence indicating why didn't we proceed with this PR back in April, do you recall?

Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yossigo please comment about the dependency and its license.

Copy link
Collaborator

@yossigo yossigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oranagra LGTM.

@filipecosta90
Copy link
Contributor Author

@filipecosta90 i see some tests are failing, please look into it. also, i don't see any correspondence indicating why didn't we proceed with this PR back in April, do you recall?

WRT to the failures, I've fixed the code/tests accordingly. Tomorrow I'll update the top comment with further data and finalized charts.

WRT to the April staleness, I guess it was due to the fact this was initially marked as a 7.2 effort?
Notice the:

"@oranagra oranagra added this to backlog in 7.2 via automation on Apr 17"

assert_encoding $encoding zscoretest
for {set i 0} {$i < $elements} {incr i} {
assert_equal [lindex $aux $i] [r zscore zscoretest $i]
assert_equal [format %.17g [lindex $aux $i]] [format %.17g [r zscore zscoretest $i]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please explain why this formatting is needed.
maybe in a code comment as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oranagra fixed it in the latest commit. Please review

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that format is used in 3 places, so the comment may be needed in all, or at least some cross reference.
but i'm still not sure i understand what changed here in that respect and why we needed that change, can you please explain

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oranagra WRT to the 3 places I've added a note on the FP representation and made reference on all 3.
WRT to why we needed that change it was because snprintf could output more digits than precision digits required to represent the number ( see https://www.ncl.ucar.edu/Support/talk_archives/2013/2176.html ). To ensure that there is no difference I'm making sure that we use the same format to compare the string representation instead of the doubles. Notice both snprintf and the grisu2 produce IEEE compliant representations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does assert_equal compare the values as strings or as floats?

If we compare the string representation, I agree they can differ for the same float value, but the float values should be equal since there are no float calculations, thus no rounding errors involved.

% expr 0.8 == 0.79999999999999999
1
% expr 0.8 == 0.8e0
1
% expr 0.79999999999999999
0.8

Therefore, I think we can compare them as floats and expect them to be equal. We can use expr to convert a string to float.

Another way is of course to convert the string to float and then back to string using format %.17g but it seems slightly more complex to me.

Btw, an implicit conversion from float to string seems to give 17 digits precision in TCL 8.6 anyway:

$ tclsh
% expr 0.12345678901234567890
0.12345678901234568
% puts [expr 0.12345678901234567890]
0.12345678901234568

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oranagra WRT

The code comments may be OK, my recent questions about the test suite changes are if you can explain here why these changes are needed.
I.e. If the new algorithm was completely compatible, no changes would be required. So I want to understand the differences.

Here's a sample of the failed test:

Expected '0.62137966259446908' to be equal to '0.6213796625944691'

Notice that the comparisons are string. If we convert them to double they represent the same number as showcased bellow:

:~# tclsh
% expr 0.62137966259446908
0.6213796625944691
% expr 0.6213796625944691
0.6213796625944691
%

Notice that the last string is the output of the grisu2, meaning we're replying in the exact IEEE required format representation.

@zuiderkwast you're indeed right. I was converting reply to double and then back to string with the format specified. I've changed the comparison towards your recommendation and there is no need to do the conversion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice that you agree. :-)

@filipecosta90
Copy link
Contributor Author

@oranagra I believe all your comments were addressed. Can you check this again?

@filipecosta90 filipecosta90 added action:run-benchmark Triggers the benchmark suite for this Pull Request and removed action:run-benchmark Triggers the benchmark suite for this Pull Request labels Oct 13, 2022
@oranagra
Copy link
Member

The code comments may be OK, my recent questions about the test suite changes are if you can explain here why these changes are needed.
I.e. If the new algorithm was completely compatible, no changes would be required. So I want to understand the differences.

@filipecosta90
Copy link
Contributor Author

The code comments may be OK, my recent questions about the test suite changes are if you can explain here why these changes are needed. I.e. If the new algorithm was completely compatible, no changes would be required. So I want to understand the differences.

@oranagra I've replied on the @zuiderkwast comment: #10587 (comment) and adjusted the comments and comparison accordingly.

@oranagra
Copy link
Member

oranagra commented Oct 14, 2022

@oranagra oranagra added the release-notes indication that this issue needs to be mentioned in the release notes label Oct 14, 2022
@oranagra oranagra merged commit 29380ff into redis:unstable Oct 15, 2022
@filipecosta90 filipecosta90 added action:run-benchmark Triggers the benchmark suite for this Pull Request and removed action:run-benchmark Triggers the benchmark suite for this Pull Request labels Oct 20, 2022
madolson pushed a commit to madolson/redis that referenced this pull request Apr 19, 2023
…ing conversion based on Florian Loitsch's Grisu-algorithm (redis#10587)

All commands / use cases that heavily rely on double to a string representation conversion,
(e.g. meaning take a double-precision floating-point number like 1.5 and return a string like "1.5" ),
could benefit from a performance boost by swapping snprintf(buf,len,"%.17g",value) by the
equivalent [fpconv_dtoa](https://github.com/night-shift/fpconv) or any other algorithm that ensures
100% coverage of conversion.

This is a well-studied topic and Projects like MongoDB. RedPanda, PyTorch leverage libraries
( fmtlib ) that use the optimized double to string conversion underneath.


The positive impact can be substantial. This PR uses the grisu2 approach ( grisu explained on
https://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf section 5 ). 

test suite changes:
Despite being compatible, in some cases it produces a different result from printf, and some tests
had to be adjusted.
one case is that `%.17g` (which means %e or %f which ever is shorter), chose to use `5000000000`
instead of 5e+9, which sounds like a bug?
In other cases, we changed TCL to compare numbers instead of strings to ignore minor rounding
issues (`expr 0.8 == 0.79999999999999999`)
enjoy-binbin pushed a commit to enjoy-binbin/redis that referenced this pull request Jul 31, 2023
…ing conversion based on Florian Loitsch's Grisu-algorithm (redis#10587)

All commands / use cases that heavily rely on double to a string representation conversion,
(e.g. meaning take a double-precision floating-point number like 1.5 and return a string like "1.5" ),
could benefit from a performance boost by swapping snprintf(buf,len,"%.17g",value) by the
equivalent [fpconv_dtoa](https://github.com/night-shift/fpconv) or any other algorithm that ensures
100% coverage of conversion.

This is a well-studied topic and Projects like MongoDB. RedPanda, PyTorch leverage libraries
( fmtlib ) that use the optimized double to string conversion underneath.


The positive impact can be substantial. This PR uses the grisu2 approach ( grisu explained on
https://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf section 5 ). 

test suite changes:
Despite being compatible, in some cases it produces a different result from printf, and some tests
had to be adjusted.
one case is that `%.17g` (which means %e or %f which ever is shorter), chose to use `5000000000`
instead of 5e+9, which sounds like a bug?
In other cases, we changed TCL to compare numbers instead of strings to ignore minor rounding
issues (`expr 0.8 == 0.79999999999999999`)
oranagra added a commit that referenced this pull request Mar 10, 2024
Since lua_Number is not explicitly an integer or a double, we need to
make an effort
to convert it as an integer when that's possible, since the string could
later be used
in a context that doesn't support scientific notation (e.g. 1e9 instead
of 100000000).

Since fpconv_dtoa converts numbers with the equivalent of `%f` or `%e`,
which ever is shorter,
this would break if we try to pass a long integer number to a command
that takes integer.
we'll get an implicit conversion to string in Lua, and then the parsing
in getLongLongFromObjectOrReply will fail.

```
> eval "redis.call('hincrby', 'key', 'field', '1000000000')" 0
(nil)
> eval "redis.call('hincrby', 'key', 'field', tonumber('1000000000'))" 0
(error) ERR value is not an integer or out of range script: ac99c32e4daf7e300d593085b611de261954a946, on @user_script:1.
```

Switch to using ll2string if the number can be safely represented as a
long long.

The problem was introduced in #10587 (Redis 7.2).
closes #13113.

---------

Co-authored-by: Binbin <binloveplay1314@qq.com>
Co-authored-by: debing.sun <debing.sun@redis.com>
Co-authored-by: Oran Agra <oran@redislabs.com>
YaacovHazan pushed a commit to YaacovHazan/redis that referenced this pull request May 16, 2024
Since lua_Number is not explicitly an integer or a double, we need to
make an effort
to convert it as an integer when that's possible, since the string could
later be used
in a context that doesn't support scientific notation (e.g. 1e9 instead
of 100000000).

Since fpconv_dtoa converts numbers with the equivalent of `%f` or `%e`,
which ever is shorter,
this would break if we try to pass a long integer number to a command
that takes integer.
we'll get an implicit conversion to string in Lua, and then the parsing
in getLongLongFromObjectOrReply will fail.

```
> eval "redis.call('hincrby', 'key', 'field', '1000000000')" 0
(nil)
> eval "redis.call('hincrby', 'key', 'field', tonumber('1000000000'))" 0
(error) ERR value is not an integer or out of range script: ac99c32e4daf7e300d593085b611de261954a946, on @user_script:1.
```

Switch to using ll2string if the number can be safely represented as a
long long.

The problem was introduced in redis#10587 (Redis 7.2).
closes redis#13113.

---------

Co-authored-by: Binbin <binloveplay1314@qq.com>
Co-authored-by: debing.sun <debing.sun@redis.com>
Co-authored-by: Oran Agra <oran@redislabs.com>
(cherry picked from commit 5fdaa53)
YaacovHazan pushed a commit that referenced this pull request May 19, 2024
Since lua_Number is not explicitly an integer or a double, we need to
make an effort
to convert it as an integer when that's possible, since the string could
later be used
in a context that doesn't support scientific notation (e.g. 1e9 instead
of 100000000).

Since fpconv_dtoa converts numbers with the equivalent of `%f` or `%e`,
which ever is shorter,
this would break if we try to pass a long integer number to a command
that takes integer.
we'll get an implicit conversion to string in Lua, and then the parsing
in getLongLongFromObjectOrReply will fail.

```
> eval "redis.call('hincrby', 'key', 'field', '1000000000')" 0
(nil)
> eval "redis.call('hincrby', 'key', 'field', tonumber('1000000000'))" 0
(error) ERR value is not an integer or out of range script: ac99c32e4daf7e300d593085b611de261954a946, on @user_script:1.
```

Switch to using ll2string if the number can be safely represented as a
long long.

The problem was introduced in #10587 (Redis 7.2).
closes #13113.

---------

Co-authored-by: Binbin <binloveplay1314@qq.com>
Co-authored-by: debing.sun <debing.sun@redis.com>
Co-authored-by: Oran Agra <oran@redislabs.com>
(cherry picked from commit 5fdaa53)
funny-dog pushed a commit to funny-dog/redis that referenced this pull request Sep 17, 2025
Since lua_Number is not explicitly an integer or a double, we need to
make an effort
to convert it as an integer when that's possible, since the string could
later be used
in a context that doesn't support scientific notation (e.g. 1e9 instead
of 100000000).

Since fpconv_dtoa converts numbers with the equivalent of `%f` or `%e`,
which ever is shorter,
this would break if we try to pass a long integer number to a command
that takes integer.
we'll get an implicit conversion to string in Lua, and then the parsing
in getLongLongFromObjectOrReply will fail.

```
> eval "redis.call('hincrby', 'key', 'field', '1000000000')" 0
(nil)
> eval "redis.call('hincrby', 'key', 'field', tonumber('1000000000'))" 0
(error) ERR value is not an integer or out of range script: ac99c32e4daf7e300d593085b611de261954a946, on @user_script:1.
```

Switch to using ll2string if the number can be safely represented as a
long long.

The problem was introduced in redis#10587 (Redis 7.2).
closes redis#13113.

---------

Co-authored-by: Binbin <binloveplay1314@qq.com>
Co-authored-by: debing.sun <debing.sun@redis.com>
Co-authored-by: Oran Agra <oran@redislabs.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action:run-benchmark Triggers the benchmark suite for this Pull Request release-notes indication that this issue needs to be mentioned in the release notes

Projects

Status: Done
Archived in project

Development

Successfully merging this pull request may close these issues.

[NEW] Performance: Improve double to string representation using Fabian Loitsch's Grisu-algorithm ( or equivalent ) without loss of precision

5 participants