gjtorikian / html-pipeline

HTML processing filters and utilities
MIT License
2.27k stars 382 forks source link

CamoFilter: use String#unpack to hexencode URLs #256

Closed glaszig closed 5 years ago

glaszig commented 8 years ago

ruby's benchmark with 100_000 iterations report some performance improvement (up to 80x on my machine) over iterating over each byte.

https://gist.github.com/glaszig/9d1975b1821a799c5db5957c4cff1539

Rehearsal -------------------------------------------------
interpolation   4.480000   0.010000   4.490000 (  4.481051)
String#unpack   0.100000   0.000000   0.100000 (  0.111963)
---------------------------------------- total: 4.590000sec

                    user     system      total        real
interpolation   4.490000   0.010000   4.500000 (  4.501468)
String#unpack   0.100000   0.000000   0.100000 (  0.109444)

        input: https://www.example.com/path/to/image.png
interpolation: 68747470733a2f2f7777772e6578616d706c652e636f6d2f706174682f746f2f696d6167652e706e67
String#unpack: 68747470733a2f2f7777772e6578616d706c652e636f6d2f706174682f746f2f696d6167652e706e67
JuanitoFatas commented 8 years ago

LGTM, @jch ?

jch commented 8 years ago

Wow, this is great. Sorry for the late response, I was out on vacation in the woods. I'll queue this up for some testing.

glaszig commented 7 years ago

any issue with this? can we get this off our plates?

jch commented 7 years ago

Sorry, work's been busy, so still haven't had time to properly test this on a live production app.

glaszig commented 5 years ago

rebased onto master. on a newer macbook (2015, the results above are from a mbp 2010), this patch is still orders of magnitude faster. lgtfm?

Rehearsal -------------------------------------------------
interpolation   3.069502   0.002232   3.071734 (  3.073401)
String#unpack   0.054645   0.000613   0.055258 (  0.055467)
---------------------------------------- total: 3.126992sec

                    user     system      total        real
interpolation   3.036294   0.001228   3.037522 (  3.038139)
String#unpack   0.053609   0.000240   0.053849 (  0.053939)

        input: https://www.example.com/path/to/image.png
interpolation: 68747470733a2f2f7777772e6578616d706c652e636f6d2f706174682f746f2f696d6167652e706e67
String#unpack: 68747470733a2f2f7777772e6578616d706c652e636f6d2f706174682f746f2f696d6167652e706e67
gjtorikian commented 5 years ago

Can't argue with numbers, thanks. Bumping this out as 2.11 now.