Opened 5 years ago

Closed 2 years ago

#10064 closed feature request (duplicate)

Add support for "foo"## literals to MagicHash

Reported by: chadaustin Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.8.4
Keywords: Cc: duncan
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Test Case:
Blocked By: Blocking:
Related Tickets: #5218 Differential Rev(s):
Wiki Page:


I'm working on a high-performance library for building up buffers of data. Appending ByteStrings works pretty well, but, for bytestring literals, it's faster to avoid the CAF (and it's associated tag check + indirect jump) entirely and append a zero-terminate MagicHash string literal via Addr#.

Then I discovered that it's 30% faster if you can avoid the strlen with an explicit length. See this benchmark:

That API is not very pleasant, of course. :)

Thus, here is a feature request:

It would be great if "foo"## produced (# Int#, Addr# #), where the Int# is the length of the buffer in bytes.

The compiler could enforce that the literal only contains 8-bit values.

Change History (6)

comment:1 Changed 5 years ago by hvr

Cc: duncan added

I think duncan may have some opinion here...

comment:2 Changed 5 years ago by simonpj

Is this the same as #5218? Which needs love.


comment:3 Changed 5 years ago by chadaustin

Hi! I don't think it's exactly the same as #5218 since I don't specifically need ByteStrings here, just a quick Int#, Addr# pair. But #5218 could definitely be implemented on top of a mechanism that desugars to this (e.g. unpackCStringLen "my literal"##).

If you'd like to merge the bugs, that's fine with me, as long as there's a way to get at some machinery to generate string length Int#s at compile time. :)

comment:4 Changed 5 years ago by simonpj

If they are different, don't merge them.

If anyone wants to take this forward, the process is as usual: write a wiki page describing the design in detail; socialise it on ghc-devs and ghc-users, refine. Then implement.


comment:5 Changed 5 years ago by thomie

Type of failure: None/UnknownRuntime performance bug

comment:6 Changed 2 years ago by bgamari

Resolution: duplicate
Status: newclosed

I think we should indeed treat this as a duplicate of #5218 as the answer proposed in comment:3 is precisely that which is being implemented in Phab:D2443.

Note: See TracTickets for help on using tickets.