Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory improvements in FastJsonNode #5088

Merged
merged 27 commits into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3f0174e
Have map for attrs
ashish-goswami Apr 1, 2020
3ae6646
Change makeScalarNode to be more clear in profile
ashish-goswami Apr 2, 2020
2b8d9f0
Remove order from fastJsonNode, as it is not getting used properly
ashish-goswami Apr 2, 2020
18b6e0b
Have composite for all fastJsonNode attributes
ashish-goswami Apr 2, 2020
f0f3034
Fix minor bug
ashish-goswami Apr 3, 2020
4df1c37
Avoid copying in arena get
ashish-goswami Apr 3, 2020
b694762
Address review comments except concurrency
ashish-goswami Apr 6, 2020
84b061b
Have interger based fastJsonNode
ashish-goswami Apr 7, 2020
0453a39
Refactor code
ashish-goswami Apr 8, 2020
f600f1d
Minor change
ashish-goswami Apr 8, 2020
2c0db78
More refactoring
ashish-goswami Apr 9, 2020
a2361da
Add benchmark for memory
ashish-goswami Apr 9, 2020
a1b50b4
Add review comments
ashish-goswami Apr 9, 2020
8e4d7c2
Minor change
ashish-goswami Apr 9, 2020
b279758
Support for multiple buffers in arena
ashish-goswami Apr 11, 2020
ade4537
Change fastJsonNode type to uint32
ashish-goswami Apr 14, 2020
fa3d15f
Have map in arena to store buffer only once
ashish-goswami Apr 14, 2020
f7e23b5
Merge remote-tracking branch 'origin/master' into ashish/globalmap
ashish-goswami Apr 14, 2020
9eb709c
Remove support for mutliple buffers in arena
ashish-goswami Apr 14, 2020
6afb8d4
Return error from Arena put if not enough space is left
ashish-goswami Apr 14, 2020
70e2a48
Return error from arena get
ashish-goswami Apr 14, 2020
aa23b71
Minor changes
ashish-goswami Apr 14, 2020
b2e7161
Have pool for arena
ashish-goswami Apr 15, 2020
ed45421
Add tests for fastJsonNode
ashish-goswami Apr 15, 2020
77f4d88
Minor changes
ashish-goswami Apr 16, 2020
d50f623
Fix deepsource warnings
ashish-goswami Apr 16, 2020
9ab57b8
Add review comments
ashish-goswami Apr 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions query/arena.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2017-2020 Dgraph Labs, Inc. and Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package query

import (
"encoding/binary"
)

type arena struct {
buf []byte
}

func newArena(size int) *arena {
a := new(arena)

// Append dummy byte to avoid reading bytes when offset is
// storing default value 0 in fastJsonNode.
a.buf = make([]byte, 0, size)
a.buf = append(a.buf, []byte("a")...)

return a
}

func (a *arena) put(b []byte) uint32 {
offset := uint32(len(a.buf)) // TODO: careful here.

// First put length of buffer, then put actual buffer. Also put length using varint encoding.
sizeBuf := make([]byte, binary.MaxVarintLen64)
w := binary.PutVarint(sizeBuf, int64(len(b)))
a.buf = append(a.buf, sizeBuf[:w]...)
a.buf = append(a.buf, b...)

return offset
}

func (a *arena) get(offset uint32) []byte {
if offset == 0 {
return nil
}

// First read length, then read actual buffer.
size, r := binary.Varint(a.buf[int(offset):])
offset += uint32(r)
// TODO: typecasting int64 to uint32 might not be safe.
return a.buf[offset : offset+uint32(size)]
}

func (a *arena) size() int {
ashish-goswami marked this conversation as resolved.
Show resolved Hide resolved
return len(a.buf) - 1 // -1 for dummy byte.
}

func (a *arena) reset() {
ashish-goswami marked this conversation as resolved.
Show resolved Hide resolved
a.buf = a.buf[:1]
}
Loading