use FastISODateParser.parseAsEpochMilli
Compared to FastISODateParser.parse, which returns an OffsetDateTime object, parseAsEpochMilli returns the epoch time millis. The performance improvement for date parsing alone is roughly 100% (8m dates/s to 18m dates/s). Insertion speed improved from 13-14s for 1.6m entries to 11.5-12.5s.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package org.lucares.pdb.api;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class Entry {
|
||||
@@ -9,30 +11,26 @@ public class Entry {
|
||||
* A special {@link Entry} that can be used as poison object for
|
||||
* {@link BlockingQueueIterator}.
|
||||
*/
|
||||
public static final Entry POISON = new Entry(OffsetDateTime.MIN, -1, null);
|
||||
public static final Entry POISON = new Entry(Long.MIN_VALUE, -1, null);
|
||||
|
||||
private final long value;
|
||||
|
||||
private final Tags tags;
|
||||
|
||||
private final OffsetDateTime date;
|
||||
private final long epochMilli;
|
||||
|
||||
public Entry(final OffsetDateTime date, final long value, final Tags tags) {
|
||||
this.date = date;
|
||||
public Entry(final long epochMilli, final long value, final Tags tags) {
|
||||
this.epochMilli = epochMilli;
|
||||
this.tags = tags;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public OffsetDateTime getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public long getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public long getEpochMilli() {
|
||||
return date.toInstant().toEpochMilli();
|
||||
return epochMilli;
|
||||
}
|
||||
|
||||
public Tags getTags() {
|
||||
@@ -45,7 +43,7 @@ public class Entry {
|
||||
return "POISON ENTRY";
|
||||
}
|
||||
|
||||
final OffsetDateTime date = getDate();
|
||||
final OffsetDateTime date = Instant.ofEpochMilli(epochMilli).atOffset(ZoneOffset.UTC);
|
||||
return date.format(DateTimeFormatter.ISO_ZONED_DATE_TIME) + " = " + value + " (" + tags.asString() + ")";
|
||||
}
|
||||
|
||||
@@ -53,7 +51,7 @@ public class Entry {
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((date == null) ? 0 : date.hashCode());
|
||||
result = prime * result + (int) (epochMilli ^ (epochMilli >>> 32));
|
||||
result = prime * result + ((tags == null) ? 0 : tags.hashCode());
|
||||
result = prime * result + (int) (value ^ (value >>> 32));
|
||||
return result;
|
||||
@@ -68,10 +66,7 @@ public class Entry {
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
final Entry other = (Entry) obj;
|
||||
if (date == null) {
|
||||
if (other.date != null)
|
||||
return false;
|
||||
} else if (!date.equals(other.date))
|
||||
if (epochMilli != other.epochMilli)
|
||||
return false;
|
||||
if (tags == null) {
|
||||
if (other.tags != null)
|
||||
@@ -82,5 +77,4 @@ public class Entry {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user