Summer of Code weekly report #3

My project

This week I followed an advice of my mentor, Simon Marlow, and started to play with the code including print statements in interesting places in order to understand it’s flow. It’s indeed much better than just reading the source code and the documentation on the wiki. As usual, I had a lot of doubts about some parts of the code, and noted them down. But now, I’m seeing that I’m resolving most of them just by playing more with the code, without need to ask in the mailing list. There are still some left, and I’m planning to send them to the list in a next oportunity.

The first thing I noticed was the high number of objects, from my perspective, that are created and collected in:

main = return ()

I measured how much times evacuate() was called. This function moves an object to the next generation of the Garbage Collector. It’s called 775 times, in 1 call to GarbageCollect(), with 479 different objects (with different pointers to their Info Tables). Also, there were pinned objects and large objects in this count. This was surprising to me.

I also made a small draw of the memory allocation in lines using diagrams. The draw:

The source code:

import Prelude hiding (tan)
import Control.Monad
import Data.Colour.RGBSpace
import Data.List
import Graphics.Rendering.Diagrams
import System.Random

objectMaxLength :: Double
objectMaxLength = 50

objectMinLength :: Double
objectMinLength = 10

nObjects :: Int
nObjects = 10

main :: IO ()
= do
— objects <- replicateM nObjects $ randomRIO (objectMinLength, objectMaxLength)
let objects = [18,50,12,46,16,41,14,30,49,23]
renderAs PNG "mem.png" Auto
$ vsep
[text 40 "(1)" <> continuous objects
, text 40 "(2)" <> lineByLine objects
, text 40 "(3)" <> allocated]

continuous :: [Double] -> Diagram
continuous = memory colors

lineByLine :: [Double] -> Diagram
lineByLine = memory (intersperse white colors ++ [white]) . objectsLine

allocated :: Diagram
= memory
(intersperse white colors ++ [white])
[18, 82, 50, 0, 12, 0, 46, 0, 16, 0, 41, 35, 14, 0, 30, 0, 49, 7, 23]

objectsLine :: [Double] -> [Double]
objectsLine [] = []
objectsLine (x : xs) = x : objectMaxLength – x : objectsLine xs

memory :: Color color => [color] -> [Double] -> Diagram
memory colours objects
= unionA
$ map (uncurry fc)
$ zip (cycle colours)
$ map (lw 0 . flip rect objectMaxLength) objects
, lines_]

lines_ :: Diagram
lines_ = hcat $ replicate nObjects $ rect objectMaxLength 50

colors :: (Ord colour, Floating colour) => [Colour colour]
= [red, green, blue, yellow, magenta, cyan
, darkred, darkgreen, darkblue, darkmagenta, darkcyan]


Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do

Você está comentando utilizando sua conta Sair / Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair / Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair / Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair / Alterar )

Conectando a %s

%d blogueiros gostam disto: