Built-in functions are still displayed in the .prof file

I am trying to figure out how to optimize the code. There he is:


{-# OPTIONS_GHC -funbox-strict-fields #-}

data Vec3 a = Vec3  !a !a !a

vx :: Vec3 a -> a
vx (Vec3 x _ _) = x
{-# SPECIALIZE INLINE vx :: Vec3 Double -> Double #-}

vy :: Vec3 a -> a
vy (Vec3 _ y _) = y
{-# SPECIALIZE INLINE vy :: Vec3 Double -> Double #-}

vz :: Vec3 a -> a
vz (Vec3 _ _ z) = z
{-# SPECIALIZE INLINE vz :: Vec3 Double -> Double #-}


dot :: (Num a) => Vec3 a -> Vec3 a -> a
dot u v = (vx u * vx v) + (vy u * vy v) + (vz u * vz v)
{-# SPECIALIZE INLINE dot :: Vec3 Double -> Vec3 Double -> Double #-}


type Vec3D = Vec3 Double

-- just make a bunch of vecs to measure performance

n = 1000000 :: Double

v1s = [Vec3 x y z | (x, y, z) <- zip3 [1 .. n] [2 .. n + 1] [3 .. n + 2]]
      :: [Vec3D]

v2s = [Vec3 x y z | (x, y, z) <- zip3 [3 .. n + 2] [2 .. n + 1] [1 .. n]]
      :: [Vec3D]


dots = zipWith dot v1s v2s  :: [Double]    
theMax = maximum dots :: Double
main :: IO ()
main = putStrLn $ "theMax: " ++ show theMax

When I compile with ghc 6.12.1 (ubuntu linux on i486 machine)

ghc --make -O2 Vec.hs -prof -auto-all -fforce-recomp

and run

Vec + RTS -p

Looking at the Vec.prof file,


COST CENTRE                    MODULE               %time %alloc

v2s                            Main                  30.9   36.5
v1s                            Main                  27.9   31.3
dots                           Main                  27.2   27.0
CAF                            GHC.Float              4.4    5.2
vy                             Main                   3.7    0.0
vx                             Main                   2.9    0.0
theMax                         Main                   2.2    0.0

I see that the vx and vy function takes up a significant part of the time.

Why? I thought the pragma SPECIALIZE INLINE these functions disappear.

When not polymorphic

data Vec3D = Vec3D {vx, vy, vz :: !Double} deriving Show

vx, vy, vz functions are not displayed as cost centers.

+5
source share
2 answers

, -auto-all, , GHC , inlining. , ​​, vx, vy vz , - ( ).

-auto-all , "-auto" SCC. SCC, let-bound , -auto-all .

+2

, , .

-, .

FUZxxl: -ddump-core , -ddump-core . , -ddump-simple, Real World Haskell, , , . "vx" .., . , . ?

: GHC , , -auto, -auto-all _scc_s INLINE. , -auto , , Vec3 /, Vec3 (Vec3), vx, vy, vz dot . Main.hs. -auto, vx, vy, vz .prof.

Re: , , , ,

data Vec3 a = Vec3 {vx, vy, vz :: !a}

vx, vy vz .prof.

+2

All Articles