haskell.nix icon indicating copy to clipboard operation
haskell.nix copied to clipboard

Performance of hsc2hs

Open angerman opened this issue 6 years ago • 7 comments

hsc2hs has an --via-asm flag. That will cause it to use its AT&T Asm parser to figure out the size of constants, ... once essential issue here is that we generate a single c file for each constant. It would be better if we generated all constants (with some identification flag) in one file, and only parsed that file. I believe this would give hsc2hs a considerable performance boost.

This is especially pronounced if a windows cross compiler builds the Win32 package which has lots of hsc2hs usage.

angerman avatar Jan 25 '19 10:01 angerman

I'm relatively unfamiliar with hsc2hs. How is haskell.nix in a position of responsibility here? This sounds like an hsc2hs issue.

ElvishJerricco avatar Jan 25 '19 18:01 ElvishJerricco

@ElvishJerricco right, this is not strictly a haskell.nix issue. As the haskell.nix issue tracker is currently the kitchen sink for us. I've just posted it here. See also the Projects tab.

angerman avatar Jan 26 '19 03:01 angerman

@angerman I'm exposed to this issue since I use several libraries that use hsc2hs heavily.

I'd like to fix this - any tips getting started?

  • How can I fork hsc2hs and have haskell.nix use my version?
  • Are there any more details/tips you can give about your proposed solution?

ramirez7 avatar Sep 28 '21 00:09 ramirez7

This issue is a slight annoyance to me. I have a few libraries (sdl2, sdl-gpu, and Win32) that end up rebuilding somewhat often and experience this issue.

I had a wild idea, but I don't know enough of hsc2hs to confidently say it would work:

What if when x-compiling to Windows, we ran the mingwW64 version of hsc2hs under wine (similar to what is done in the iserv wrapper). Then it could run in "direct" mode and bypass this issue altogether. I'm guessing more work may also need to be done to make sure hsc2hs is using the correct C compiler as well, but it feels like we'd have access to that since we are generating valid target code at the end of the day.

I assume the same trick could work for other cross targets with enough work to emulate hsc2hs's work on the host.


The idea in the OP about generating one file also seems promising (and not that hard to do - hsc2hs is a pretty straightforward Haskell program).

Either way, it feels like I would be able to just set the --with-hsc2hs cabal flag in my code's haskell-nix.defaultModules to try out my custom hsc2hs (if I understand the attribute correctly).

ramirez7 avatar Sep 15 '22 22:09 ramirez7

Was there any update to hsc2hs lately? I'm noticing that hsc2hs is substantially faster when x-compiling to mingwW64 now.

ramirez7 avatar Jul 02 '23 02:07 ramirez7

Was there any update to hsc2hs lately? I'm noticing that hsc2hs is substantially faster when x-compiling to mingwW64 now.

Did you change compiler versions? Hsc2hs is usually shipped with GHC and the one package that's really slow is the Win32 package.

angerman avatar Jul 02 '23 09:07 angerman

I bumped to 9.2.8.

Win32 is slow, but sdl-gpu (library I wrote bindings for which uses a lot of hsc2hs) was also pretty slow (like walk away and come back slow) but now it is fine. Maybe this is just faulty memory on my part though.

ramirez7 avatar Jul 02 '23 19:07 ramirez7