{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreicpyg7hj5gyruxzxnn4jet5wvzd6bczmm5l7ajo5qh5iddfkejnya",
"uri": "at://did:plc:pi6woz4d47bkuws673w2il2r/app.bsky.feed.post/3mkcq3ngno6n2"
},
"path": "/t/help-with-optimization-profiling/13982#post_1",
"publishedAt": "2026-04-25T07:34:49.000Z",
"site": "https://discourse.haskell.org",
"tags": [
"minimal test case"
],
"textContent": "I have a Haskell program that generates an .svg file with an embedded (base64-encoded) png in it.\n\nFor a 5000x5000 image it takes about 2s to generate the svg. I’m not sure if I can get it any faster, so I created a minimal test case and ran it with profiling on.\n\nspeedscope gave the following results:\n\nSo _clearly_ my `imageBytes` function is the main performance culprit. The left half of it is just JuicyPixels’ png generation at work. The right half is time spent in the function itself (I think). The function itself is very simple though:\n\n\n imageBytes :: SizedImage -> (Float -> Pixel8) -> BSL.ByteString\n imageBytes img convertPixel = do\n let image =\n generateImage\n (\\x y -> convertPixel $ img.entries SV.! ((img.height - y - 1) * img.width + x))\n img.width\n img.height\n case encodePalettedPng viridisPalette image of\n Right v -> v\n Left e -> error e\n\n\n(`convertPixel` takes an entry from `img.entries :: Vector Float` and normalizes it using the min/max pixel value in the image).\n\nNow I am stuck a bit. How do I go deeper into profiling? In other words, what to do after speedscope exhausted its usefulness?",
"title": "Help with optimization/profiling"
}