Skip to content

ToEncodedUrlPiece#50

Merged
fizruk merged 3 commits intomasterfrom
toEncodedUrlPiece
Apr 10, 2017
Merged

ToEncodedUrlPiece#50
fizruk merged 3 commits intomasterfrom
toEncodedUrlPiece

Conversation

@fizruk
Copy link
Copy Markdown
Owner

@fizruk fizruk commented Apr 10, 2017

This PR is based on #47 and adds efficient implementations for toEncodedUrlPiece together with some tests.

@phadej could you take a look?

@fizruk
Copy link
Copy Markdown
Owner Author

fizruk commented Apr 10, 2017

We could also implement more efficient versions of toEncodedUrlPiece for Maybe and Either... but I wonder who uses those anyway.

@phadej
Copy link
Copy Markdown
Collaborator

phadej commented Apr 10, 2017

Seems fine. Have you benchmarked (or do you real world example) that this really matters?

@fizruk
Copy link
Copy Markdown
Owner Author

fizruk commented Apr 10, 2017

I did not perform a proper benchmarking, but it should matter, considering that URL-encoding demands per-char processing. A quick test in GHCi reveals at least some difference:

>>> :set +s
>>> import qualified Data.ByteString.Lazy as BSL
>>> import Data.ByteString.Builder (toLazyByteString)
>>> let check f = sum . map (BSL.length . toLazyByteString . f)
>>> check (toEncodedUrlPiece . toUrlPiece) [1..10000000]
68888897
(22.59 secs, 72,137,670,104 bytes)
>>> check toEncodedUrlPiece [1..10000000]
68888897
(15.44 secs, 55,719,891,472 bytes)

OTOH, now that I think of it,toEncodedUrlPiece only happens on clients, so it probably isn't much of a performance concern.

Copy link
Copy Markdown
Collaborator

@phadej phadej left a comment

Choose a reason for hiding this comment

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

LGTM

@fizruk fizruk merged commit 19f79be into master Apr 10, 2017
@fizruk fizruk deleted the toEncodedUrlPiece branch April 10, 2017 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants