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

Reduce the size of Duration to 8 bytes #4858

Merged
merged 25 commits into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
086767f
Reduce the size of `Duration` to 8 bytes
iosmanthus Jun 7, 2019
deb1997
Add benchmark for `Duration`
iosmanthus Jun 12, 2019
e0845d7
Rewrite `checked_add/checked_sub` for `Duration`
iosmanthus Jun 12, 2019
c560f99
Mask the unused bit
iosmanthus Jun 12, 2019
6bbae15
Add `to_bits/from_bits` for `Duration`
iosmanthus Jun 13, 2019
e0494f1
Set `subsec_nanos` to private
iosmanthus Jun 13, 2019
50b3409
Set `subsec_nanos` back to public...
iosmanthus Jun 13, 2019
0e1356c
Merge branch 'master' into refactor-duration
iosmanthus Jun 13, 2019
149d754
Rename `as_*` to `to_*`
iosmanthus Jun 14, 2019
8504383
Merge branch 'master' into refactor-duration
breezewish Jun 14, 2019
7749b68
Merge branch 'master' into refactor-duration
breezewish Jun 17, 2019
74291b0
Remove `Duration::build`
iosmanthus Jun 19, 2019
9b45575
Reuse some code
iosmanthus Jun 24, 2019
d7b99ee
Rename `Duration::fmt` to `Duration::format`
iosmanthus Jun 24, 2019
92cdc4d
Merge branch 'master' into refactor-duration
iosmanthus Jun 24, 2019
258a592
Merge remote-tracking branch 'upstream/master' into refactor-duration
iosmanthus Jun 24, 2019
20b00d9
Merge branch 'master' into refactor-duration
breezewish Jun 29, 2019
8675b16
Fix unit test failing in rpn function module
iosmanthus Jun 29, 2019
282eb34
Merge branch 'refactor-duration' of github.com:iosmanthus/tikv into r…
iosmanthus Jun 29, 2019
42d67ec
Merge branch 'master' into refactor-duration
breezewish Jul 1, 2019
6b85b74
Use `write!` to format `Duration`
iosmanthus Jul 1, 2019
6f9ae4e
Merge remote-tracking branch 'upstream/master' into refactor-duration
iosmanthus Jul 1, 2019
0c1dff2
Merge branch 'refactor-duration' of github.com:iosmanthus/tikv into r…
iosmanthus Jul 1, 2019
64872e4
Impl TryFrom<Duration> for Decimal
iosmanthus Jul 1, 2019
1346a64
Merge branch 'master' into refactor-duration
breezewish Jul 3, 2019
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
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ twoway = "0.2.0"
ordered-float = "1.0"
nom = "5.0.0-beta1"
servo_arc = "0.1.1"
bitfield = "0.13.2"
profiler = { path = "components/profiler" }
mime = "0.3.13"
match_template = { path = "components/match_template" }
Expand Down
4 changes: 2 additions & 2 deletions components/tikv_util/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn duration_to_sec(d: Duration) -> f64 {

/// Converts Duration to nanoseconds.
#[inline]
pub fn duration_to_nanos(d: Duration) -> u64 {
pub fn duration_as_nanos(d: Duration) -> u64 {
breezewish marked this conversation as resolved.
Show resolved Hide resolved
let nanos = u64::from(d.subsec_nanos());
// Most of case, we can't have so large Duration, so here just panic if overflow now.
d.as_secs() * 1_000_000_000 + nanos
Expand Down Expand Up @@ -435,7 +435,7 @@ mod tests {
let exp_sec = ms as f64 / 1000.0;
let act_sec = duration_to_sec(d);
assert!((act_sec - exp_sec).abs() < f64::EPSILON);
assert_eq!(ms * 1_000_000, duration_to_nanos(d));
assert_eq!(ms * 1_000_000, duration_as_nanos(d));
}
}

Expand Down
8 changes: 4 additions & 4 deletions fuzz/targets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,15 @@ fn fuzz_duration(
let _ = t.hours();
let _ = t.minutes();
let _ = t.secs();
let _ = t.micro_secs();
let _ = t.nano_secs();
let _ = t.to_secs();
let _ = t.subsec_micros();
let _ = t.subsec_nanos();
let _ = t.as_secs_f64();
let _ = t.is_zero();
let _ = t.to_decimal();
let u = t;
u.round_frac(cursor.read_as_i8()?)?;
let mut v = Vec::new();
let _ = v.encode_duration(&t);
let _ = v.encode_duration(t);
Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions src/coprocessor/codec/chunk/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Column {
Datum::F64(v) => self.append_f64(*v),
Datum::Bytes(ref v) => self.append_bytes(v),
Datum::Dec(ref v) => self.append_decimal(v),
Datum::Dur(ref v) => self.append_duration(v),
Datum::Dur(v) => self.append_duration(*v),
Datum::Time(ref v) => self.append_time(v),
Datum::Json(ref v) => self.append_json(v),
_ => Err(box_err!("unsupported datum {:?}", data)),
Expand Down Expand Up @@ -280,7 +280,7 @@ impl Column {
}

/// Append a duration datum to the column.
pub fn append_duration(&mut self, d: &Duration) -> Result<()> {
pub fn append_duration(&mut self, d: Duration) -> Result<()> {
self.data.encode_duration(d)?;
self.finish_append_fixed()
}
Expand Down
2 changes: 1 addition & 1 deletion src/coprocessor/codec/data_type/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ impl VectorValue {
}
Some(ref val) => {
output.push(datum::DURATION_FLAG);
output.encode_i64(val.to_nanos())?;
output.encode_i64(val.as_nanos())?;
}
}
Ok(())
Expand Down
16 changes: 8 additions & 8 deletions src/coprocessor/codec/datum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl Datum {
Datum::U64(u) => self.cmp_u64(ctx, u),
Datum::F64(f) => self.cmp_f64(ctx, f),
Datum::Bytes(ref bs) => self.cmp_bytes(ctx, bs),
Datum::Dur(ref d) => self.cmp_dur(ctx, d),
Datum::Dur(d) => self.cmp_dur(ctx, d),
Datum::Dec(ref d) => self.cmp_dec(ctx, d),
Datum::Time(ref t) => self.cmp_time(ctx, t),
Datum::Json(ref j) => self.cmp_json(j),
Expand Down Expand Up @@ -173,7 +173,7 @@ impl Datum {
cmp_f64(ff, f)
}
Datum::Dur(ref d) => {
let ff = d.to_secs();
let ff = d.as_secs_f64();
cmp_f64(ff, f)
}
Datum::Time(ref t) => {
Expand Down Expand Up @@ -225,14 +225,14 @@ impl Datum {
}
}

fn cmp_dur(&self, ctx: &mut EvalContext, d: &Duration) -> Result<Ordering> {
fn cmp_dur(&self, ctx: &mut EvalContext, d: Duration) -> Result<Ordering> {
match *self {
Datum::Dur(ref d2) => Ok(d2.cmp(d)),
Datum::Dur(ref d2) => Ok(d2.cmp(&d)),
Datum::Bytes(ref bs) => {
let d2 = Duration::parse(bs, MAX_FSP)?;
Ok(d2.cmp(d))
Ok(d2.cmp(&d))
}
_ => self.cmp_f64(ctx, d.to_secs()),
_ => self.cmp_f64(ctx, d.as_secs_f64()),
}
}

Expand Down Expand Up @@ -386,7 +386,7 @@ impl Datum {
Datum::I64(i) => i,
Datum::U64(u) => u as i64,
Datum::F64(f) => f.to_bits() as i64,
Datum::Dur(ref d) => d.to_nanos(),
Datum::Dur(ref d) => d.as_nanos(),
Datum::Time(_)
| Datum::Bytes(_)
| Datum::Dec(_)
Expand Down Expand Up @@ -904,7 +904,7 @@ pub trait DatumEncoder: BytesEncoder + DecimalEncoder + JsonEncoder {
}
Datum::Dur(ref d) => {
self.write_u8(DURATION_FLAG)?;
self.encode_i64(d.to_nanos())?;
self.encode_i64(d.as_nanos())?;
}
Datum::Dec(ref d) => {
self.write_u8(DECIMAL_FLAG)?;
Expand Down
Loading