Skip to content

Conversation

@laines-it
Copy link
Collaborator

This commit reduces allocations.

Future.done allocation replaced with

  • Future.cond (*sync.Cond)
  • Future.finished (atomic.Bool)

Other code use Future.isDone() instead Future.done == nil check.

Added Future.finish() marks Future as done.
Future.WaitChan() now creates channel on demand.

Closes #496

This commit reduces allocations.

Future.done allocation replaced with
- Future.cond (*sync.Cond)
- Future.finished (atomic.Bool)

Other code use Future.isDone() instead (Future.done == nil) check.

Added Future.finish() marks Future as done.
Future.WaitChan() now creates channel on demand.

Closes #496
@laines-it laines-it force-pushed the laines-it/gh-496-replace-Future-chan-cond-Sync branch from dd9e78b to f5ce75f Compare December 2, 2025 14:34
@laines-it laines-it marked this pull request as draft December 2, 2025 14:35
@laines-it laines-it marked this pull request as ready for review December 2, 2025 14:41
Copy link
Collaborator

@oleg-jukovec oleg-jukovec left a comment

Choose a reason for hiding this comment

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

Thanks for the patch. Overall, everything's fine.

I've added some implementation notes, but you need to do a proper rebase first.

Future.pushes[], Future.ready (#480, #497).
* `LogAppendPushFailed` replaced with `LogBoxSessionPushUnsupported` (#480)
* `LogAppendPushFailed` replaced with `LogBoxSessionPushUnsupported` (#480).
* Removed deprecated `Connection` methods, related interfaces and tests are updated (#479).
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like rebase artifacts.

Comment on lines +19 to +33
*NOTE*: due to Future.GetTyped() doesn't decode SelectRequest into structure, substitute Connection.GetTyped() following the example:
```Go
var singleTpl = Tuple{}
err = conn.GetTyped(space, index, key, &singleTpl)
```
At now became:
```Go
var tpl []Tuple
err = conn.Do(NewSelectRequest(space).
Index(index).
Limit(1).
Key(key)
).GetTyped(&tpl)
singleTpl := tpl[0]
```
Copy link
Collaborator

Choose a reason for hiding this comment

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

And here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

etc

Comment on lines +155 to +157
if fut.done == nil {
fut.done = make(chan struct{})
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a code-style issue.

Suggested change
if fut.done == nil {
fut.done = make(chan struct{})
}
if fut.done == nil {
fut.done = make(chan struct{})
}

close(fut.done)
}

fut.cond.Broadcast()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
fut.cond.Broadcast()
fut.cond.Broadcast()

case conn.rlimit <- struct{}{}:
case <-fut.done:
default:
<-fut.WaitChan()
Copy link
Collaborator

@oleg-jukovec oleg-jukovec Dec 2, 2025

Choose a reason for hiding this comment

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

It should look like this:

Suggested change
<-fut.WaitChan()
default:
select{
case conn.rlimit <- struct{}{}:
case <-fut.WaitChan():
if fut.err == nil {
panic("fut.done is closed, but err is nil")
}
}

mutex sync.Mutex
resp Response
err error
cond *sync.Cond
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
cond *sync.Cond
cond sync.Cond

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v3: replace channel in Future with a cond.Sync

3 participants