perf timing

This commit is contained in:
NatureFreshMilk 2019-01-22 13:17:30 +01:00
parent 607c4fe06d
commit bf841f6ba0
5 changed files with 40 additions and 15 deletions

View File

@ -27,7 +27,7 @@ func getKey(pos coords.MapBlockCoords) string {
}
func NewMapBlockAccessor(accessor db.DBAccessor) *MapBlockAccessor {
c := cache.New(100*time.Millisecond, 200*time.Millisecond)
c := cache.New(500*time.Millisecond, 1000*time.Millisecond)
return &MapBlockAccessor{accessor: accessor, c: c}
}
@ -60,6 +60,7 @@ func (a *MapBlockAccessor) FindLegacyMapBlocks(lastpos coords.MapBlockCoords, li
for _, l := range layerfilter {
if (block.Pos.Y*16) >= l.From && (block.Pos.Y*16) <= l.To {
inLayer = true
break
}
}

View File

@ -41,11 +41,11 @@ func (mb *MapBlock) GetNodeName(x, y, z int) string {
return mb.BlockMapping[id]
}
func NewMapblock() MapBlock {
func NewMapblock() *MapBlock {
mb := MapBlock{}
mb.Metadata = NewMetadata()
mb.BlockMapping = make(map[int]string)
return mb
return &mb
}
func NewMetadata() *Metadata {

View File

@ -40,14 +40,14 @@ func Parse(data []byte, mtime int64, pos coords.MapBlockCoords) (*MapBlock, erro
offset = 6
//metadata
count, err := parseMapdata(&mapblock, data[offset:])
count, err := parseMapdata(mapblock, data[offset:])
if err != nil {
return nil, err
}
offset += count
count, err = parseMetadata(&mapblock, data[offset:])
count, err = parseMetadata(mapblock, data[offset:])
if err != nil {
return nil, err
}
@ -86,5 +86,5 @@ func Parse(data []byte, mtime int64, pos coords.MapBlockCoords) (*MapBlock, erro
mapblock.BlockMapping[nodeId] = blockName
}
return &mapblock, nil
return mapblock, nil
}

View File

@ -156,30 +156,32 @@ func (tr *TileRenderer) RenderImage(tc *coords.TileCoords, recursionDepth int) (
}
log.WithFields(fields).Debug("Quad image stats")
start := time.Now()
upperLeft, _, err := tr.RenderImage(quads.UpperLeft, recursionDepth-1)
if err != nil {
panic(err)
//return nil, err
return nil, nil, err
}
upperRight, _, err := tr.RenderImage(quads.UpperRight, recursionDepth-1)
if err != nil {
panic(err)
//return nil, err
return nil, nil, err
}
lowerLeft, _, err := tr.RenderImage(quads.LowerLeft, recursionDepth-1)
if err != nil {
panic(err)
//return nil, err
return nil, nil, err
}
lowerRight, _, err := tr.RenderImage(quads.LowerRight, recursionDepth-1)
if err != nil {
panic(err)
//return nil, err
return nil, nil, err
}
t := time.Now()
quadrender := t.Sub(start)
start = t
img := image.NewNRGBA(
image.Rectangle{
image.Point{0, 0},
@ -211,11 +213,34 @@ func (tr *TileRenderer) RenderImage(tc *coords.TileCoords, recursionDepth int) (
draw.Draw(img, rect, resizedImg, image.ZP, draw.Src)
}
t = time.Now()
quadresize := t.Sub(start)
start = t
buf := new(bytes.Buffer)
png.Encode(buf, img)
t = time.Now()
encode := t.Sub(start)
start = t
tile := mapobjectdb.Tile{Pos: tc, Data: buf.Bytes(), Mtime: time.Now().Unix()}
tr.tdb.SetTile(&tile)
t = time.Now()
cache := t.Sub(start)
fields = logrus.Fields{
"X": tc.X,
"Y": tc.Y,
"Zoom": tc.Zoom,
"LayerId": tc.LayerId,
"quadrender": quadrender,
"quadresize": quadresize,
"encode": encode,
"cache": cache,
}
log.WithFields(fields).Debug("Cross stitch")
return img, buf.Bytes(), nil
}

View File

@ -95,5 +95,4 @@ func TestTileRender(t *testing.T) {
f, _ = os.Create("../output/0_0_13.png")
bytes.NewReader(data).WriteTo(f)
}