Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

perf: avoid double checkingvalue0 Future.#10972

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
He-Pin wants to merge1 commit intoscala:2.13.x
base:2.13.x
Choose a base branch
Loading
fromHe-Pin:futureAwait

Conversation

He-Pin
Copy link
Contributor

Motivation:

The currentFuture.isComplete check thevalue0 once, and then it will checked it again to extract the value.

Modification:

Use.value to extract the value at the same time.

Result:
Better performance when the future is already completed.

[info] Benchmark                                                 (pool)  (recursion)  (threads)   Mode  Cnt        Score        Error   Units[info] CompleteFutureBenchmark.success                              fix         1024          1  thrpt    5   990403.006 ±   6431.624  ops/ms[info] CompleteFutureBenchmark.success:gc.alloc.rate                fix         1024          1  thrpt    5        0.001 ±      0.001  MB/sec[info] CompleteFutureBenchmark.success:gc.alloc.rate.norm           fix         1024          1  thrpt    5       ≈ 10⁻⁶                 B/op[info] CompleteFutureBenchmark.success:gc.count                     fix         1024          1  thrpt    5          ≈ 0               counts[info] CompleteFutureBenchmark.successOption                        fix         1024          1  thrpt    5  1265272.145 ± 336165.695  ops/ms[info] CompleteFutureBenchmark.successOption:gc.alloc.rate          fix         1024          1  thrpt    5        0.001 ±      0.001  MB/sec[info] CompleteFutureBenchmark.successOption:gc.alloc.rate.norm     fix         1024          1  thrpt    5       ≈ 10⁻⁶                 B/op[info] CompleteFutureBenchmark.successOption:gc.count               fix         1024          1  thrpt    5          ≈ 0               counts[info] CompleteFutureBenchmark.successUnwrap                        fix         1024          1  thrpt    5  1322735.278 ±  25844.808  ops/ms[info] CompleteFutureBenchmark.successUnwrap:gc.alloc.rate          fix         1024          1  thrpt    5        0.001 ±      0.001  MB/sec[info] CompleteFutureBenchmark.successUnwrap:gc.alloc.rate.norm     fix         1024          1  thrpt    5       ≈ 10⁻⁶                 B/op[info] CompleteFutureBenchmark.successUnwrap:gc.count               fix         1024          1  thrpt    5          ≈ 0               counts`

The result ifsuccessOption with this modification.

I still checked adding anFuture#unwrap = value0() method to avoid the lifting toSome/None ,but seems not help much.

@He-Pin
Copy link
ContributorAuthor

[error] -- [E149] Syntax Error: /home/travis/build/scala/scala/target/library/src_managed/main/scala3-library-src/scala/Matchable.scala:7:6 [error] 7 |trait Matchable[error]   |      ^^^^^^^^^[error]   |      illegal redefinition of standard class Matchable[error]   |[error]   | longer explanation available when compiling with `-explain`[error] -- [E149] Syntax Error: /home/travis/build/scala/scala/target/library/src_managed/main/scala3-library-src/scala/AnyKind.scala:7:21 [error] 7 |final abstract class AnyKind[error]   |                     ^^^^^^^[error]   |                     illegal redefinition of standard class AnyKind[error]   |[error]   | longer explanation available when compiling with `-explain`[error] -- [E007] Type Mismatch Error: /home/travis/build/scala/scala/src/library/scala/concurrent/package.scala:203:45 [error] 203 |      case CompletedFuture(result) => result.get[error]     |                                      ^^^^^^^^^^[error]     |                                      Found:    Any[error]     |                                      Required: T[error]     |

@He-Pin
Copy link
ContributorAuthor

refs:scala/scala3#22304

@SethTisueSethTisue added the library:concurrentChanges to the concurrency support in stdlib labelJan 6, 2025
@@ -170,7 +173,7 @@ package concurrent {
@throws(classOf[TimeoutException])
@throws(classOf[InterruptedException])
final def ready[T](awaitable: Awaitable[T], atMost: Duration): awaitable.type = awaitable match {
case f: Future[T] if f.isCompleted => awaitable.ready(atMost)(AwaitPermission)
case f: Future[T] if f.isCompleted => awaitable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It seems we still want to validate the duration

#7767 was closed for that reason, in favor of#7768

He-Pin reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks, just back from hometown , will check this weekend

@SethTisueSethTisue marked this pull request as draftFebruary 4, 2025 04:39
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@lrytzlrytzlrytz left review comments

Assignees
No one assigned
Labels
library:concurrentChanges to the concurrency support in stdlib
Projects
None yet
Milestone
2.13.17
Development

Successfully merging this pull request may close these issues.

4 participants
@He-Pin@lrytz@SethTisue@scala-jenkins

[8]ページ先頭

©2009-2025 Movatter.jp