Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,351
    • Issues 5,351
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 567
    • Merge requests 567
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Merge requests
  • !4901

Ppr: compute length of string literals at compile time (#19266)

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Sylvain Henry requested to merge hsyl20/ghc:hsyl20/perf/strlen into master Jan 27, 2021
  • Overview 4
  • Commits 1
  • Pipelines 3
  • Changes 1

Commit message:

SDoc string literals created for example with `text "xyz"` are converted
into `PtrString` (`Addr#` + size in bytes) with a rewrite rule to avoid
allocating a String.

Before this patch, the size in bytes was still computed at runtime. For
every literal, we obtained the following pseudo STG:

    x :: Addr#
    x = "xzy"#

    s :: PtrString
    s = \u [] case ffi:strlen [x realWorld#] of
            (# _, sz #) -> PtrString [x sz]

But since GHC 9.0, we can use `cstringLength#` instead to get:

    x :: Addr#
    x = "xzy"#

    s :: PtrString
    s = PtrString! [x 3#]

Literals become statically known constructor applications. Allocations
seem to decrease a little in perf tests (between -0.1% and -0.7% on CI).
Edited Jan 27, 2021 by Sylvain Henry
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: hsyl20/perf/strlen