You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to do reasonably fast character escaping in Haskell (that is, within a few factors of C). Using [plain `ByteString` manipulation][1], my Haskell implementation is 125 times slower than my C implementation. Then I tried to use [blaze-builder][2]. That was even slower.
1
+
I'm trying to do reasonably fast character escaping in Haskell (that is, within a few factors of C). Using [plain ByteString manipulation][1], my Haskell implementation is 125 times slower than my C implementation. Then I tried to use [blaze-builder][2]. That was even slower.
2
2
3
-
I eventually managed to get it to about 1.5 times slower than the C version (very good!). However, it uses a lot of ugly buffer manipulation, and the performance boost is very sensitive to what gets inlined and what doesn't.
4
-
5
-
The key function is this:
3
+
I eventually managed to get it to about 1.5 times slower than the C version (very good!). The key function is this:
It is like [concatMap from Data.ByteString][3]. However, instead of the callback returning a `ByteString`, it returns a [Write][4] object (defined in the [blaze-builder][5] package), which is used to write the data directly into a buffer.
7
+
It is like [concatMap from Data.ByteString][3]. However, instead of the callback returning a [ByteString][6], it returns a [Write][4] which is used to write the data directly into a buffer.
8
+
9
+
However, there are two problems:
10
+
11
+
* It uses a lot of ugly buffer manipulation,
12
+
13
+
* The performance boost is very sensitive to what gets inlined and what doesn't.
10
14
11
15
Is there a better way to translate a sequence of bytes in Haskell than this?
12
16
@@ -19,3 +23,5 @@ Is there a better way to translate a sequence of bytes in Haskell than this?
0 commit comments