[Git][ghc/ghc][master] Reduce parser allocations in allocateCommentsP

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Sun Feb 4 08:56:38 UTC 2024



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
0df8ce27 by Vladislav Zavialov at 2024-02-04T03:55:14-05:00
Reduce parser allocations in allocateCommentsP

In the most common case, the comment queue is empty, so we can skip the
work of processing it. This reduces allocations by about 10% in the
parsing001 test.

Metric Decrease:
    MultiLayerModulesRecomp
    parsing001

- - - - -


2 changed files:

- compiler/GHC/Parser/Lexer.x
- compiler/GHC/Parser/PostProcess.hs


Changes:

=====================================
compiler/GHC/Parser/Lexer.x
=====================================
@@ -3235,6 +3235,7 @@ instance MonadP P where
   getBit ext = P $ \s -> let b =  ext `xtest` pExtsBitmap (options s)
                          in b `seq` POk s b
   allocateCommentsP ss = P $ \s ->
+    if null (comment_q s) then POk s emptyComments else  -- fast path
     let (comment_q', newAnns) = allocateComments ss (comment_q s) in
       POk s {
          comment_q = comment_q'


=====================================
compiler/GHC/Parser/PostProcess.hs
=====================================
@@ -3060,6 +3060,7 @@ instance MonadP PV where
       let b = ext `xtest` pExtsBitmap (pv_options ctx) in
       PV_Ok acc $! b
   allocateCommentsP ss = PV $ \_ s ->
+    if null (pv_comment_q s) then PV_Ok s emptyComments else  -- fast path
     let (comment_q', newAnns) = allocateComments ss (pv_comment_q s) in
       PV_Ok s {
          pv_comment_q = comment_q'



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0df8ce27f1c418fee1ba860f1c6575f66cae2ca7

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0df8ce27f1c418fee1ba860f1c6575f66cae2ca7
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240204/54cda5b2/attachment-0001.html>


More information about the ghc-commits mailing list