-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(s3stream): optimize StreamRecordBatchList to reduce object creation
1. remove ArrayList copy when create instance. 2. only create ComparableStreamRecordBatch when call get. 3. reduce java primitive type compare for Long.
- Loading branch information
1 parent
4192785
commit 7087857
Showing
4 changed files
with
87 additions
and
20 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
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
23 changes: 23 additions & 0 deletions
23
...eam/src/main/java/com/automq/stream/utils/biniarysearch/primitive/LongComparableItem.java
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,23 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 com.automq.stream.utils.biniarysearch.primitive; | ||
|
||
public interface LongComparableItem { | ||
boolean isLessThan(long value); | ||
|
||
boolean isGreaterThan(long value); | ||
} |
45 changes: 45 additions & 0 deletions
45
.../src/main/java/com/automq/stream/utils/biniarysearch/primitive/LongOrderedCollection.java
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,45 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 com.automq.stream.utils.biniarysearch.primitive; | ||
|
||
public abstract class LongOrderedCollection { | ||
|
||
protected abstract int size(); | ||
|
||
protected abstract LongComparableItem get(int index); | ||
|
||
public int search(long target) { | ||
int low = 0; | ||
int high = size() - 1; | ||
while (low <= high) { | ||
int mid = low + ((high - low) >>> 1); | ||
LongComparableItem midVal = get(mid); | ||
if (midVal.isLessThan(target)) { | ||
low = mid + 1; | ||
} else if (midVal.isGreaterThan(target)) { | ||
high = mid - 1; | ||
} else { | ||
low = mid; | ||
break; | ||
} | ||
} | ||
if (low > high) { | ||
return -1; | ||
} | ||
return low; | ||
} | ||
} |