Skip to content

runtime: aggregate defer #2364

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

Closed
rsc opened this issue Oct 12, 2011 · 10 comments
Closed

runtime: aggregate defer #2364

rsc opened this issue Oct 12, 2011 · 10 comments

Comments

@rsc
Copy link
Contributor

rsc commented Oct 12, 2011

defer does 1 malloc + explicit free per deferred call.
should aggregate them into chunks.
@dvyukov
Copy link
Member

dvyukov commented Oct 13, 2011

Comment 1:

I would consider allocating Defers on stack (if number of args is limited)

@davecheney
Copy link
Contributor

Comment 2:

If that were possible it would be wonderful. Even for zero arg functions it would be
extremely useful. 
Sent from my iPad

@dvyukov
Copy link
Member

dvyukov commented Oct 13, 2011

Comment 3:

I am sure it is possible in some [common] cases. It will require some amount CFG
analysis, since apparently (?) one can't do that if defer is executed in a loop.
I guess the function usually needs at least a receiver (mu.Unlock(), f.Close()). There
is no significant difference between 1 and N args.

@rsc
Copy link
Contributor Author

rsc commented Oct 13, 2011

Comment 4:

I don't think allocating them on the stack will have much benefit
over allocating them on a separate stack.  The key point is to
aggregate the allocations and frees.

@dvyukov
Copy link
Member

dvyukov commented Oct 17, 2011

Comment 5:

Compiler is able to handle any number of args w/o hardcoding any limits, and I think it
is able to avoid 2 copies of args. However per-M stack of Defers for at most, say, 4
args is much simpler and is able to handle loops, so I agree that it is the way to go.

@rsc
Copy link
Contributor Author

rsc commented Dec 9, 2011

Comment 6:

Labels changed: added priority-later.

@rsc
Copy link
Contributor Author

rsc commented Jan 29, 2012

Comment 7:

Labels changed: added performance.

@rsc
Copy link
Contributor Author

rsc commented Sep 12, 2012

Comment 8:

Labels changed: added go1.1.

@rsc
Copy link
Contributor Author

rsc commented Dec 10, 2012

Comment 9:

Labels changed: added size-l.

@rsc
Copy link
Contributor Author

rsc commented Dec 22, 2012

Comment 10:

This issue was closed by revision 0de7161.

Status changed to Fixed.

@rsc rsc self-assigned this Dec 22, 2012
@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants