-
Notifications
You must be signed in to change notification settings - Fork 201
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
Pg Client: improve Interval support #1462
Merged
Merged
Conversation
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 a preliminary commit related to issue eclipse-vertx#1281 Encoding and decoding an Interval implied creating many objects (Duration and Period are immutable). Besides, the Duration.plusXXX and Period.normalized methods perform several computations. With the proposed change: - the codec doesn't create redundant objects - a decoded interval is always normalized (i.e. the number of months is strictly smaller than 12, the number of days is strictly smaller than 30,... etc). Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
Not ready yet, do not merge |
The test compares the previous and the proposed solutions. It confirms the assumptions about the proposed solution: - about twice as fast - removes pressure on GC # JMH version: 1.19 # VM version: JDK 1.8.0_422, VM 25.422-b05 # VM options: -Xms8g -Xmx8g -Xmn7g # Warmup: 20 iterations, 1 s each # Measurement: 10 iterations, 2 s each # Timeout: 10 min per iteration # Threads: 1 thread, will synchronize iterations # Benchmark mode: Throughput, ops/time Benchmark Mode Cnt Score Error Units IntervalBenchmarks.encodeWithDurationAndPeriod thrpt 30 46339.530 ± 389.115 ops/ms IntervalBenchmarks.encodeWithDurationAndPeriod:·gc.alloc.rate thrpt 30 3393.324 ± 28.481 MB/sec IntervalBenchmarks.encodeWithDurationAndPeriod:·gc.alloc.rate.norm thrpt 30 96.000 ± 0.001 B/op IntervalBenchmarks.encodeWithDurationAndPeriod:·gc.churn.PS_Eden_Space thrpt 30 3436.887 ± 778.345 MB/sec IntervalBenchmarks.encodeWithDurationAndPeriod:·gc.churn.PS_Eden_Space.norm thrpt 30 97.302 ± 22.205 B/op IntervalBenchmarks.encodeWithDurationAndPeriod:·gc.churn.PS_Survivor_Space thrpt 30 0.005 ± 0.006 MB/sec IntervalBenchmarks.encodeWithDurationAndPeriod:·gc.churn.PS_Survivor_Space.norm thrpt 30 ≈ 10⁻⁴ B/op IntervalBenchmarks.encodeWithDurationAndPeriod:·gc.count thrpt 30 36.000 counts IntervalBenchmarks.encodeWithDurationAndPeriod:·gc.time thrpt 30 30.000 ms IntervalBenchmarks.encodeWithParts thrpt 30 82322.542 ± 109.306 ops/ms IntervalBenchmarks.encodeWithParts:·gc.alloc.rate thrpt 30 ≈ 10⁻⁴ MB/sec IntervalBenchmarks.encodeWithParts:·gc.alloc.rate.norm thrpt 30 ≈ 10⁻⁶ B/op IntervalBenchmarks.encodeWithParts:·gc.count thrpt 30 ≈ 0 counts Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
tsegismont
changed the title
Pg Client: conversion of Duration to/from Interval
Pg Client: improve Interval support
Sep 9, 2024
The conversion algorithm assumes a year last 12 months and a month lasts 30 days, as Postgres does and ISO 8601 suggests. See https://github.com/postgres/postgres/blob/5bbdfa8a18dc56d3e64aa723a68e02e897cb5ec3/src/include/datatype/timestamp.h#L116 Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
This is ready for review, PTAL @vietj |
tsegismont
commented
Sep 16, 2024
vertx-pg-client/src/main/java/io/vertx/pgclient/data/Interval.java
Outdated
Show resolved
Hide resolved
tsegismont
commented
Sep 16, 2024
vertx-pg-client/src/main/java/io/vertx/pgclient/data/Interval.java
Outdated
Show resolved
Hide resolved
tsegismont
added a commit
to tsegismont/vertx-sql-client
that referenced
this pull request
Sep 16, 2024
* Refactor Pg Interval codec This a preliminary commit related to issue eclipse-vertx#1281 Encoding and decoding an Interval implied creating many objects (Duration and Period are immutable). Besides, the Duration.plusXXX and Period.normalized methods perform several computations. With the proposed change: - the codec doesn't create redundant objects - a decoded interval is always normalized (i.e. the number of months is strictly smaller than 12, the number of days is strictly smaller than 30,... etc). Signed-off-by: Thomas Segismont <tsegismont@gmail.com> * Added a JMH test for Interval encoding The test compares the previous and the proposed solutions. It confirms the assumptions about the proposed solution: - about twice as fast - removes pressure on GC # JMH version: 1.19 # VM version: JDK 1.8.0_422, VM 25.422-b05 # VM options: -Xms8g -Xmx8g -Xmn7g # Warmup: 20 iterations, 1 s each # Measurement: 10 iterations, 2 s each # Timeout: 10 min per iteration # Threads: 1 thread, will synchronize iterations # Benchmark mode: Throughput, ops/time Benchmark Mode Cnt Score Error Units IntervalBenchmarks.encodeWithDurationAndPeriod thrpt 30 46339.530 ± 389.115 ops/ms IntervalBenchmarks.encodeWithDurationAndPeriod:·gc.alloc.rate thrpt 30 3393.324 ± 28.481 MB/sec IntervalBenchmarks.encodeWithDurationAndPeriod:·gc.alloc.rate.norm thrpt 30 96.000 ± 0.001 B/op IntervalBenchmarks.encodeWithDurationAndPeriod:·gc.churn.PS_Eden_Space thrpt 30 3436.887 ± 778.345 MB/sec IntervalBenchmarks.encodeWithDurationAndPeriod:·gc.churn.PS_Eden_Space.norm thrpt 30 97.302 ± 22.205 B/op IntervalBenchmarks.encodeWithDurationAndPeriod:·gc.churn.PS_Survivor_Space thrpt 30 0.005 ± 0.006 MB/sec IntervalBenchmarks.encodeWithDurationAndPeriod:·gc.churn.PS_Survivor_Space.norm thrpt 30 ≈ 10⁻⁴ B/op IntervalBenchmarks.encodeWithDurationAndPeriod:·gc.count thrpt 30 36.000 counts IntervalBenchmarks.encodeWithDurationAndPeriod:·gc.time thrpt 30 30.000 ms IntervalBenchmarks.encodeWithParts thrpt 30 82322.542 ± 109.306 ops/ms IntervalBenchmarks.encodeWithParts:·gc.alloc.rate thrpt 30 ≈ 10⁻⁴ MB/sec IntervalBenchmarks.encodeWithParts:·gc.alloc.rate.norm thrpt 30 ≈ 10⁻⁶ B/op IntervalBenchmarks.encodeWithParts:·gc.count thrpt 30 ≈ 0 counts Signed-off-by: Thomas Segismont <tsegismont@gmail.com> * Interval conversion from/to Duration The conversion algorithm assumes a year last 12 months and a month lasts 30 days, as Postgres does and ISO 8601 suggests. See https://github.com/postgres/postgres/blob/5bbdfa8a18dc56d3e64aa723a68e02e897cb5ec3/src/include/datatype/timestamp.h#L116 Signed-off-by: Thomas Segismont <tsegismont@gmail.com> * Update vertx-pg-client/src/main/java/io/vertx/pgclient/data/Interval.java * Update vertx-pg-client/src/main/java/io/vertx/pgclient/data/Interval.java --------- Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Faster and garbage-free codec, compatibility with
java.time.Duration
Closes #1281
Commits can be reviewed individually.