-
-
Notifications
You must be signed in to change notification settings - Fork 110
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
Make it possible to set growth size #96
Comments
However, I wouldn't expect a |
As I understand it, both types allocate in 4k chunks. If I'm creating mind of small objects then either a lot of copying will be needed or a lot of small chunks - and at that point the append operation inside Allocate becomes expensive. |
It would be good to have a benchmark demonstrating the problem, if you can provide a small reproducible case that demonstrates the issue. As a workaround, you can implement the |
Given an idl like this:
And a benchmark like this:
You get this:
In other words, both the single segment and the multi segment implementations are pretty slow. Interestingly, the multisegment is actually slower than single segment for some reason. The Grow case is using a custom Arena implementation like you suggested. Basically it will grow each segment to be double size of the previous segment:
|
I rewrote the benchmark slightly (since I want the amount of work to be fixed): func BenchmarkSnapshotSingle(b *testing.B) {
const (
fieldValue = "1234567" // carefully chosen to be word-padded
rootMessageOverhead = 8 * 3 // root pointer, Document struct, composite list tag
perFieldOverhead = 8 * 2 // Field struct, fieldValue + "\0"
numElements = 64 * 1024
totalSize = rootMessageOverhead + perFieldOverhead*numElements
)
b.SetBytes(totalSize)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, seg, _ := capnp.NewMessage(capnp.SingleSegment(nil))
doc, _ := air.NewRootAllocBenchmark(seg)
d, _ := doc.NewFields(numElements)
for j := 0; j < numElements; j++ {
d.At(j).SetStringValue(fieldValue)
}
}
}
// etc I also added another implementation for single slice that mimics the
I'll clean this up and submit it into master. Thanks for writing up the benchmark! |
Not making algorithm changes yet to establish a baseline. Updates #96
Right now, there's a fixed growth size of 4k. If you're allocating a lot of small objects in a segment that's too small, it's really slow as it is right now. Sometimes it's really hard to predict the final size up front, so making it possible to grow in bigger chunks would be great.
Same goes for new segments in a MultiSegment.
The text was updated successfully, but these errors were encountered: