forked from golang/geo
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MB-54131: Geoshape query decode optimization (#14)
* MB-54131: Geoshape query decode optimization - Added buffer pool pointer to polygon - Added parent polygon pointer to loop - Added decoder function to select, populate and return a pointer to the buffer from a pool of buffers - Updated loop decode function to handle chunks of data being read - Updated polygon decode function to pass on the buffer pool to the loops - Updated extractShapesFromBytes and FilterGeoShapesOnRelation to include the buffer pool in its parameters * MB-54131: Geoshape query decode optimization - Changed buffer pool from pointer to slice - Removed randomly formatted comments * MB-54131: Geoshape query decode + add .gitignore * MB-54131: Geoshape query decode optimization - Added a buffer pool struct - Increased size of the maximum buffer to 24KB - Added better comments * MB-54131: Geoshape query decode optimization - Minor formatting fixes - Reusing buffers instead of creating everytime * MB-54131: Geoshape query decode optimization - Better comments - Removed some magic numbers * MB-54131: Geoshape query decode optimization - Changed buffer pool implementation to give the smallest buffer that fits the data completely - Changed decoder implementation to allow buffer sizes bigger than number of bytes needed * MB-54131: Geoshape query decode optimization - Renamed some constants * MB-54131: Geoshape query decode optimization - Added benchmark for loop decode
- Loading branch information
Showing
7 changed files
with
182 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) 2023 Couchbase, Inc. | ||
// | ||
// 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 s2 | ||
|
||
// GeoBufferPool represents a pool of buffers ranging from a given | ||
// max size to a min size in steps of 2. It uses a lazy approach only allocating | ||
// the buffers when it is needed. | ||
|
||
type GeoBufferPool struct { | ||
buffers [][]byte | ||
maxSize int | ||
minSize int | ||
} | ||
|
||
func NewGeoBufferPool(maxSize int, minSize int) *GeoBufferPool { | ||
// Calculating the number of buffers required. Assuming that | ||
// the value of minSize is correct, the buffers will be of size | ||
// minSize, 2 * minSize, 4 * minSize and so on till it is less | ||
// than or equal to the maxSize. If it is not equal to maxSize, | ||
// then a suitable value less than maxSize will be set as maxSize | ||
length := 0 | ||
temp := minSize | ||
for temp <= maxSize { | ||
length = length + 1 | ||
temp = temp * 2 | ||
} | ||
maxSize = temp / 2 | ||
|
||
return &GeoBufferPool{ | ||
buffers: make([][]byte, length), | ||
maxSize: maxSize, | ||
minSize: minSize, | ||
} | ||
} | ||
|
||
func (b *GeoBufferPool) Get(size int) ([]byte) { | ||
bufSize := b.minSize | ||
|
||
for i := range b.buffers { | ||
if size <= bufSize || i == len(b.buffers) - 1{ | ||
if b.buffers[i] == nil { | ||
b.buffers[i] = make([]byte, bufSize) | ||
} | ||
|
||
return b.buffers[i] | ||
} else { | ||
bufSize = bufSize * 2 | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters