Hello,
Voting is now open for the weak references RFC.
The RFC and patch can be found here:
https://wiki.php.net/rfc/weakreferences
You can vote here:
https://wiki.php.net/rfc/weakreferences/vote
I don't seem to be able to vote myself and I'm not sure if that's an
error or not.
Regards,
Hannes Landeholm
Hi,
I like this idea. But I'd like to ask something; maybe someone could
please correct the Example section of RFC?
Unfortunately, I cannot understand how it could work on "else"
conditional block, because $obj is undefined.
Cheers,
Hello,
Voting is now open for the weak references RFC.
The RFC and patch can be found here:
https://wiki.php.net/rfc/weakreferencesYou can vote here:
https://wiki.php.net/rfc/weakreferences/voteI don't seem to be able to vote myself and I'm not sure if that's an
error or not.Regards,
Hannes Landeholm
--
--
Guilherme Blanco
Mobile: +55 (11) 8118-4422
MSN: guilhermeblanco@hotmail.com
São Paulo - SP/Brazil
Sorry that this was unclear,
$obj is defined in the comment that says "// compute $obj"
Imagine a SQL query there or otherwise code that constructs $obj from
an external data source.
Regards,
Hannes
On 1 August 2011 20:27, guilhermeblanco@gmail.com
guilhermeblanco@gmail.com wrote:
Hi,
I like this idea. But I'd like to ask something; maybe someone could
please correct the Example section of RFC?
Unfortunately, I cannot understand how it could work on "else"
conditional block, because $obj is undefined.Cheers,
Hello,
Voting is now open for the weak references RFC.
The RFC and patch can be found here:
https://wiki.php.net/rfc/weakreferencesYou can vote here:
https://wiki.php.net/rfc/weakreferences/voteI don't seem to be able to vote myself and I'm not sure if that's an
error or not.Regards,
Hannes Landeholm
--
--
Guilherme Blanco
Mobile: +55 (11) 8118-4422
MSN: guilhermeblanco@hotmail.com
São Paulo - SP/Brazil
Hello,
I would just like to remind you that the voting will take place for 7
more days so there are still time to discuss your concerns. If you
find something confusing or have objections I would be very interested
in hearing them and discussing that before you vote as I have
reminded you twice now during the 2 week discussion period. Remember
that people want this feature, so the least you can do is explain your
objections before you vote no. Silently burying feature requests does
not help anybody.
aharvey: I'm surprised you voted no since you seemed content with the
answers you got earlier. Do you have some special objection in mind?
Cheers,
~Hannes
aharvey: I'm surprised you voted no since you seemed content with the
answers you got earlier. Do you have some special objection in mind?
Sorry, I meant to send an e-mail last night explaining the -1 and
completely forgot before I went to bed. I guess it may be moot now,
but for the record...
I've no issue with the answer that you gave to my earlier question,
but I agree with Stas (and apparently Etienne): I'm not really
convinced this needs to be in mainline at the moment. I don't doubt
that weak references have the potential to be useful, but given this
can be implemented in PECL, I'd rather revisit this once there's more
data on how useful this is this the community as a whole — it's not
something I've personally ever needed in PHP or even really heard
anyone ask for, outside of the feature request linked in the RFC
(which is about 115th on the overall list of feature requests sorted
by vote, although I don't think the voting system is remotely
representative anyway).
If the implementation works out well there, there's no reason we can't
revisit the bundling decision for 5.5 next year, but it's a lot easier
to get something in than remove something later. There are a number of
packages that have been promoted after getting use in PECL (json, zip
and PDO spring to mind immediately), so it's a well-worn path.
Adam
hi,
You have to start a new thread to begin a vote, see the voting RFC. So
everyone will see it.
However, I feel like it is premature to vote on that one. For one, I'm
not convinced by this feature yet. I'm not sure it is the right way to
do it, or if it is actually needed. The more I look at it the more I
would recommend you to go with a pecl package, get feedbacks from the
actual users (framework&co) and come back once you have reached more
maturity with both the design and the implementation of this feature.
Don't be afraid to miss 5.4 either, next one comes next year :)
Cheers,
Hello,
Voting is now open for the weak references RFC.
The RFC and patch can be found here:
https://wiki.php.net/rfc/weakreferencesYou can vote here:
https://wiki.php.net/rfc/weakreferences/voteI don't seem to be able to vote myself and I'm not sure if that's an
error or not.Regards,
Hannes Landeholm
--
--
Pierre
@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
Hello,
hi,
You have to start a new thread to begin a vote, see the voting RFC. So
everyone will see it.However, I feel like it is premature to vote on that one. For one, I'm
not convinced by this feature yet. I'm not sure it is the right way to
do it, or if it is actually needed. The more I look at it the more I
would recommend you to go with a pecl package, get feedbacks from the
actual users (framework&co) and come back once you have reached more
maturity with both the design and the implementation of this feature.
I'll make a PECL ext based on this patch. That should make this RFC/vote moot.
Best,
Don't be afraid to miss 5.4 either, next one comes next year :)
Cheers,
Hello,
Voting is now open for the weak references RFC.
The RFC and patch can be found here:
https://wiki.php.net/rfc/weakreferencesYou can vote here:
https://wiki.php.net/rfc/weakreferences/voteI don't seem to be able to vote myself and I'm not sure if that's an
error or not.Regards,
Hannes Landeholm
--
--
Pierre@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
--
--
Etienne Kneuss
http://www.colder.ch
However, I feel like it is premature to vote on that one. For one, I'm
not convinced by this feature yet. I'm not sure it is the right way to
do it, or if it is actually needed.
Using weak references is the only way to design non caching references
and the only way to correctly implement the observer pattern without
leaking memory as outlined in the RFC. I need this feature and 12
others also do who voted on bug #52318. For everyone that votes on a
ticket there's probably a hundred others who also needed it but didn't
find the ticket, didn't bother creating an account or didn't bother
voting. When it's hard to contribute people won't bother. I'm trying
to speak for the users that have too little time to argue in mailing
lists or write RFC's or learn C or jump trough endless hoops in a
process designed so that the core development team can ignore the
community more democratically. The users that just suck it up and
design their applications or frameworks poorly instead because they
don't have time.
I can also tell some of my own experience as an additional use case.
Since this feature did not exist I was forced to implement caching
referencing in my framework which resulted in huge memory problems
during certain object intensive procedures. An application I developed
for a customer crashed when it bumped into 330 MB of memory. I had to
resort to unsetting stuff manually - basically making hacks which did
memory management - which is not something you're suppose to be
required to do in a memory managed language like PHP. I anticipated
this problem when designing my framework but could not do anything
about it since PHP did not provide me with the necessary tools to
actually solve it.
As Ethan Nicolas puts it in the last sentence of this paragraph:
""This might look okay on the surface, but the strong reference to
widget will almost certainly cause problems. We have to know (with
100% certainty) when a particular Widget's serial number is no longer
needed, so we can remove its entry from the map. Otherwise we're going
to have a memory leak (if we don't remove Widgets when we should) or
we're going to inexplicably find ourselves missing serial numbers (if
we remove Widgets that we're still using). If these problems sound
familiar, they should: they are exactly the problems that users of
non-garbage-collected languages face when trying to manage memory, and
we're not supposed to have to worry about this in a more civilized
language like Java.""
Just as "classes is not needed when you have arrays with functions in
them", is week references is not needed "when you can implement ugly
memory management unset hacks". A language should provide the tools a
programmer need to design their applications well. Currently I am
unable to design my applications well because PHP does not support
designing my ID-to-object-referencing-component well because PHP does
not support weak references.
Tell me how I should design an application so that you can get an
"already initialized object" for a certain ID while enabling the GC to
collect it without using weak referencing. Then I'll be convinced that
the feature "is not needed".
The more I look at it the more I
would recommend you to go with a pecl package, get feedbacks from the
actual users (framework&co) and come back once you have reached more
maturity with both the design and the implementation of this feature.
I'm not sure how to respond to that. "The more I look at it" does not
parse as an actual argument of anything in my head. Be more specific.
I strongly disagree that Weak References should be buried in a PECL
extension. I speak for a lot of PHP developers when I say that I don't
want to have anything to do with PECL. I'm a programmer - I don't want
to spend valuable time compiling and configuring anything. Compiling
is a nightmare for most PHP developers - especially on Windows. A
developer is a user - if it's not simple to develop he will move to
other frameworks or languages. PECL is great for experimental, complex
stuff like APC or very specific types of integration and purposes. Not
specific language features - they should be implemented in the
language. Nobody likes writing platform-dependent code.
Also I'm not sure what you expect when you say that it "reached more
maturity". To what end? A feature doesn't really get much more well
defined and simple than this. It's like the whole "it's a single class
with two functions" and "it's implemented as a fundamental component
in other major OO languages" counts for nothing. Like all other
languages perhaps accidentally implemented it without actually needing
it and now we need to discuss the feature again endlessly and "gather
community feedback" for years even though all the research has already
been done. It will be simple to extend the class with additional
methods if other use cases should emerge.
Don't be afraid to miss 5.4 either, next one comes next year :)
I've been a PHP fan for years and endured the patchy OO implementation
and the limitations that has come with the language for the
simplicity. Unfortunately I don't have time to wait for years even if
many of you guys do. If I did I wouldn't have bothered writing the RFC
or writing in this mailing list. You guys should look into this new
rapid release cycle thing. It's the next iteration of software
development.
~Hannes
hi,
You have to start a new thread to begin a vote, see the voting RFC. So
everyone will see it.However, I feel like it is premature to vote on that one. For one, I'm
not convinced by this feature yet. I'm not sure it is the right way to
do it, or if it is actually needed. The more I look at it the more I
would recommend you to go with a pecl package, get feedbacks from the
actual users (framework&co) and come back once you have reached more
maturity with both the design and the implementation of this feature.Don't be afraid to miss 5.4 either, next one comes next year :)
Cheers,
Hello,
Voting is now open for the weak references RFC.
The RFC and patch can be found here:
https://wiki.php.net/rfc/weakreferencesYou can vote here:
https://wiki.php.net/rfc/weakreferences/voteI don't seem to be able to vote myself and I'm not sure if that's an
error or not.Regards,
Hannes Landeholm
--
--
Pierre@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
Hannes Landeholm wrote:
I've been a PHP fan for years and endured the patchy OO implementation
and the limitations that has come with the language for the
simplicity. Unfortunately I don't have time to wait for years even if
many of you guys do. If I did I wouldn't have bothered writing the RFC
or writing in this mailing list. You guys should look into this new
rapid release cycle thing. It's the next iteration of software
development.
The fast development root does seem to have been a little screwed up recently,
but if there is nothing in an extension that requires direct access to the core
and that extension CAN simply be enabled as required, then pecl is the way to
go? We do need the pecl area to be properly included in the build process with
windows builds being created just as they used to be, but the process is working
fine for APC and perhaps the plan should be to moving some more extensions that
are being worked on between PHP releases into the pecl process? It used to be
that many of the extensions I used were managed in pecl ... and I'd be quite
happy if they moved back there. There is nothing stopping 'Weak References'
being added by those who want them ... but I can't see the point myself when
running scripts live.
--
Lester Caine - G8HFL
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php
I've talked to Etienne and he still believes we should vote on this so the
vote is still up. He just replied to quickly. If the vote fails the patch
can still be implemented in a PECL extension. There's no point canceling the
vote or the RFC - it's still valid and ongoing, and there is still time for
discussion.
The problem is that PECL is not an option for all users. If you're using
shared hosting and otherwise don't have control over what extensions is
loaded or not then essentially you'll be unable to use a framework that
takes advantage of weak references. That's the reality of many freelancing
developers and small-scale sites out there. It's especially problematic for
framework designers that builds ORM-layers - they can't tell their users "oh
btw you need to install this non standard PECL extension for it to work". Or
rather, you can but then the user will be angry.
I don't think "because they can" is a good argument for why features should
generally be outsourced as PECL extensions. Complex, experimental stuff that
solves specific integration or performance problems is great for PECL. But
generic object orientation design fundamentals should be implemented in the
core since people rather have their framework leak a bit more memory (and
risk running out of it in edge cases) or design their application more
clumsy than depend on a non-standard PECL extension. It's about allowing
people to do elegant design. A good developer would choose compatibility
over elegant design any day - so if the language wants people to do design
great applications the language needs to provide those tools natively.
I realize I need to provide some kind of realistic scenario for you to
understand so let's put ourselves in the shoes of Joe Codeguy - he's
currently designing the an application that will edit inventory details at a
small company with 10 employees. It is hosted at a shared hosting provider
since they are running a tight budget. They can't afford their own servers
or an IT guy. The employers regularly login to the application and updates
the inventory. Joe Codeguy has designed the application so that there are
one Product class that is loaded from the database where each "products"
table row corresponds to a product. Certain function in the application runs
a MySQL procedure that updates a certain complex selection of products in
the products database rendering the currently loaded products in memory
obsolete since they might have been updated. After this procedure runs all
Product class objects in memory will need to be reloaded. Joe Codeguy fixes
this by implementing the observer pattern (PEAR Event_Dispatcher) so that
whenever a Product is loaded or created it registers itself on a global
event called "EVENT_PRODUCT_RELOAD". He then proceeds to trigger the event
whenever the complex MySQL procedure updates the database table. Everything
seems to be working fine so he deploys the application. One days later the
customer complains that a certain critical operation no longer works. Joe
then find a subroutine while debugging that loops trough a quite large
selection of thousands of products one by one and makes some complicated
calculations. During this loop the application faces a out of memory
condition. Joe thinks this is strange because it only operates on one
product at a time. He then realizes that the observer registration prevents
the products from being garbage collected properly since they are strongly
referenced by Event_Dispatcher. Thankfully PHP implements weak references so
he can correct Event_Dispatcher to use weak referencing instead. However
it's outsourced into a PECL extension and since Joe cannot install
extensions into the production server he is forced to use unset hacks in the
faulty loops to correct the issue. Joe deploys the application again and can
only hope that this was the only loop that triggered the memory problem and
that the application doesn't crash anywhere else when the products table
grows larger.
Also even if an application doesn't run out of memory there might be a
serious performance impact from the memory leaked by objects that can't be
collected properly. If an application peaks at 15 MB instead of 25 MB, the
server can run 40% more child threads in parallel.
Regards,
~Hannes
The fast development root does seem to have been a little screwed up
recently, but if there is nothing in an extension that requires direct
access to the core and that extension CAN simply be enabled as required,
then pecl is the way to go? We do need the pecl area to be properly included
in the build process with windows builds being created just as they used to
be, but the process is working fine for APC and perhaps the plan should be
to moving some more extensions that are being worked on between PHP releases
into the pecl process? It used to be that many of the extensions I used were
managed in pecl ... and I'd be quite happy if they moved back there. There
is nothing stopping 'Weak References' being added by those who want them ...
but I can't see the point myself when running scripts live.--
Lester Caine - G8HFLContact - http://lsces.co.uk/wiki/?page=**contacthttp://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/**index.php<http://www.firebirdsql.org/index.php
Hello,
I've talked to Etienne and he still believes we should vote on this so the
vote is still up. He just replied to quickly. If the vote fails the patch
can still be implemented in a PECL extension. There's no point canceling the
vote or the RFC - it's still valid and ongoing, and there is still time for
discussion... snip ...
I think at this point everyone is well aware that you would like this
feature implemented.
I would like to make a couple points here, first I is that PECL is not
a place for a extension to rot, that statement makes absolutely no
sense to me. PDO I recall years ago getting from PECL, Http a
extension I often use, was recently on this list if I recall to be
moved into the core. I'm sure there are plenty of people on this list
that were part of extension's PECL -> CORE lifecycles that could add
several more examples to the list. I believe PECL Would be a great
place for something like this that was is entirely understood or has
overwhelming support in my opinion. I am really not sure how
comfortable I am with a feature as new as this being in the PHP on my
servers. Some form of incubation, testing and use feedback only makes
sense to me.
Second I would like to talk a little bit about weak references for
those who are not familiar with them or have thus far only read your
very strong pro-opinion. I would like to make it very clear with the
simple fact that weak references are not required, ever by any
language. They are a convenience, not a solution to a unsolvable
problem. I believe that if anything weak references encourage laziness
in design, it causes the referential integrity that I am accustomed to
is broken, and can often lead to more code and checks then it
relieves. It is very easy to run into unexpected bugs and in a
language like PHP, where you don't get a NPE when you try to access a
NULL
method of a non object, you get a fatal error, this doesn't seem
very appealing to me. Only under very specific cases of caching
patterns as you have previously mentioned is such a pattern even
recognized to -have a place for use that isn't just plain wrong- -not
a requirement- by me.
In PHP, I believe a web or cli app that uses enough resources to bomb
memory limits on a server, needs to be re-factored. I have definitely
written multi-process PHP daemons that go to disk or over the network
for taxing operations that need cached and had very little trouble
with rudimentary memory management patterns, so from my perspective I
can't really see why given the toolset PHP provides that this is such
a problem.
This is just my opinion, I don't have a strong opposition to this
feature, anything "new" to PHP I usually get excited about, I simply
wanted to give a few counter arguments as the fact that this feature
is being presented as a dire and long over due missing feature to the
language is a bit dramatic. Not saying its useless and doesn't belong
in PHP or I would never want it to exists, I just would hate to see
something rushed through that didn't get a bit of testing and typical
QA from a language that affects millions of people.
-Chris
I would like to make a couple points here, first I is that PECL is not
a place for a extension to rot, that statement makes absolutely no
sense to me. PDO I recall years ago getting from PECL, Http a
extension I often use, was recently on this list if I recall to be
moved into the core. I'm sure there are plenty of people on this list
that were part of extension's PECL -> CORE lifecycles that could add
several more examples to the list. I believe PECL Would be a great
place for something like this that was is entirely understood or has
overwhelming support in my opinion.
I don't agree with the concept of putting new feature in PECL itself.
I would happily agree with putting it there if actually believed that
it was there it belonged.
Theoretically speaking weak references is a core feature since it
touches on garbage collection. If you followed the discussion the last
weeks you'll see that the patch was intentionally weakened in
functionality so no changes would have to be made to the GC (The
"catch collection event" feature was removed/not implemented.). The
reason behind this was so that it would not require much testing and
have a larger chance of being merged into 5.4. This had the side
effect of making it technically implementable as a PECL extension
which was never intended. Rather I feel like this is instead used as
an opportunity to delay it because it is difficult to put yourself in
the situation of the marginal number of PHP developers that needs it.
Yes, I admit that the number of people that care about the feature and
knows what weak references are can be described as "marginal" but I
also believe all frustrations are worth taking a shot at - especially
the frustrations of the more advanced developer segment of the
community. If they are not given the tools they need to implement the
great design they envision they will look for other tools=languages
instead and move on. The more great programmers that wants to use PHP
the better position PHP has as a language and community. Also I think
WR will have a huge impact when frameworks, event handlers, observer
abstractions etc implements weak references and reduces the memory
usage on a lot of applications out there.
I am really not sure how
comfortable I am with a feature as new as this being in the PHP on my
servers. Some form of incubation, testing and use feedback only makes
sense to me.
If you don't use weak references there's no risk that anything breaks.
The alpha and RC stage is exactly what incubation, testing and
feedback is for.
Second I would like to talk a little bit about weak references for
those who are not familiar with them or have thus far only read your
very strong pro-opinion. I would like to make it very clear with the
simple fact that weak references are not required, ever by any
language. They are a convenience, not a solution to a unsolvable
problem. I believe that if anything weak references encourage laziness
in design, it causes the referential integrity that I am accustomed to
is broken, and can often lead to more code and checks then it
relieves.
No. Weak References is a solution to an unsolvable problem. The
problem is a subset of "decoupling" or "separation of concerns" theory
in OOP. An example of the problem can be stated like this:
- You need to design a framework in PHP. The framework should be
decoupled from the application that uses it. This means that the data
the application requests is undefined from the frameworks perspective.
It should contain an ORM layer that maps exactly one object instance
to a certain table row. If the frameworks fails to do this the
application will have parallel instances of the same object row which
is a corrupt data state. The application requests object instances by
ID selection. The application may request a large number of object
instances but never references more than what can be kept in memory at
the same time. Design the ORM layer so that the application never
faces an OOM condition.
You may have the opinion that object oriented design problems aren't
"real problems". Fundamentally, design patterns does not solve any
pure mathematical problems. Design patterns does not allow you to sort
faster than O(n log n). Rather they solve an economical problem. By
giving programmers the tools they need to write elegant code, the code
becomes easier to understand, test and maintain. It saves the
developer's time and the company's money. And most importantly, it
makes programming fun. ;)
It is very easy to run into unexpected bugs and in a
language like PHP, where you don't get a NPE when you try to access a
NULL
method of a non object, you get a fatal error, this doesn't seem
very appealing to me. Only under very specific cases of caching
patterns as you have previously mentioned is such a pattern even
recognized to -have a place for use that isn't just plain wrong- -not
a requirement- by me.
So if a language feature allows a programmer to write more messier
code the language should not provide those features? I disagree with
that.
In PHP, I believe a web or cli app that uses enough resources to bomb
memory limits on a server, needs to be re-factored. I have definitely
written multi-process PHP daemons that go to disk or over the network
for taxing operations that need cached and had very little trouble
with rudimentary memory management patterns, so from my perspective I
can't really see why given the toolset PHP provides that this is such
a problem.
It's not a mathematical problem. Yes you can still design your code so
that it breaks responsibilities and decoupling. You can write special
unset functions and document that they need to be called whenever
objects are "not used anymore". If you're mainly a C programmer I also
understand your indifference to having the userland developer worry
about memory management. However, I think PHP should be a civilized
language that takes care of stuff like that.
This is just my opinion, I don't have a strong opposition to this
feature, anything "new" to PHP I usually get excited about, I simply
wanted to give a few counter arguments as the fact that this feature
is being presented as a dire and long over due missing feature to the
language is a bit dramatic. Not saying its useless and doesn't belong
in PHP or I would never want it to exists, I just would hate to see
something rushed through that didn't get a bit of testing and typical
QA from a language that affects millions of people.
I had a two week discussion period that was mostly silent and I felt
the consensus was generally in favor of the feature which is why I
started the vote. It's a single class with two functions. It
implements a widely researched and adopted design pattern. It's not a
new or experimental concept. It will get "a bit of testing" and it has
been given opportunity of "typical QA" like other features voted for
an accepted into 5.4.
~Hannes
I had a two week discussion period that was mostly silent and I felt
the consensus was generally in favor of the feature which is why I
started the vote.
@internals silence on new features can be interpreted both ways.
Looking at the general feeling now I think it is time to accept the
feature will be in PECL. Later you can come back and renew discussion
about core inclusion. To push the topic too far right now will only
antagonize folk. The best path forward is to make sure the extension
has good code coverage, works in all possible PHP branches, is kept up
to date, and is picked up by some good PHP projects.
I know everyone here appreciates the time and constructive arguments
you have put into this and would like to make sure you keep
contributing to PHP. You've got a lot further than some feature
proposers have in the past so take some credit for your efforts.
Chris
--
Email: christopher.jones@oracle.com
Tel: +1 650 506 8630
Blog: http://blogs.oracle.com/opal/
Tired...
I don't agree with the concept of putting new feature in PECL itself...
should of course be:
I don't disagree with the concept of putting new feature in PECL itself...
~Hannes
Adding a new feature to the latest version of PHP will not make it
available to users of shared hosting. Many of these are running on older
versions and it takes time for them to get updated to the latest.
- Frank
I've talked to Etienne and he still believes we should vote on this so the
vote is still up. He just replied to quickly. If the vote fails the patch
can still be implemented in a PECL extension. There's no point canceling the
vote or the RFC - it's still valid and ongoing, and there is still time for
discussion.The problem is that PECL is not an option for all users. If you're using
shared hosting and otherwise don't have control over what extensions is
loaded or not then essentially you'll be unable to use a framework that
takes advantage of weak references. That's the reality of many freelancing
developers and small-scale sites out there. It's especially problematic for
framework designers that builds ORM-layers - they can't tell their users "oh
btw you need to install this non standard PECL extension for it to work". Or
rather, you can but then the user will be angry.I don't think "because they can" is a good argument for why features should
generally be outsourced as PECL extensions. Complex, experimental stuff that
solves specific integration or performance problems is great for PECL. But
generic object orientation design fundamentals should be implemented in the
core since people rather have their framework leak a bit more memory (and
risk running out of it in edge cases) or design their application more
clumsy than depend on a non-standard PECL extension. It's about allowing
people to do elegant design. A good developer would choose compatibility
over elegant design any day - so if the language wants people to do design
great applications the language needs to provide those tools natively.I realize I need to provide some kind of realistic scenario for you to
understand so let's put ourselves in the shoes of Joe Codeguy - he's
currently designing the an application that will edit inventory details at a
small company with 10 employees. It is hosted at a shared hosting provider
since they are running a tight budget. They can't afford their own servers
or an IT guy. The employers regularly login to the application and updates
the inventory. Joe Codeguy has designed the application so that there are
one Product class that is loaded from the database where each "products"
table row corresponds to a product. Certain function in the application runs
a MySQL procedure that updates a certain complex selection of products in
the products database rendering the currently loaded products in memory
obsolete since they might have been updated. After this procedure runs all
Product class objects in memory will need to be reloaded. Joe Codeguy fixes
this by implementing the observer pattern (PEAR Event_Dispatcher) so that
whenever a Product is loaded or created it registers itself on a global
event called "EVENT_PRODUCT_RELOAD". He then proceeds to trigger the event
whenever the complex MySQL procedure updates the database table. Everything
seems to be working fine so he deploys the application. One days later the
customer complains that a certain critical operation no longer works. Joe
then find a subroutine while debugging that loops trough a quite large
selection of thousands of products one by one and makes some complicated
calculations. During this loop the application faces a out of memory
condition. Joe thinks this is strange because it only operates on one
product at a time. He then realizes that the observer registration prevents
the products from being garbage collected properly since they are strongly
referenced by Event_Dispatcher. Thankfully PHP implements weak references so
he can correct Event_Dispatcher to use weak referencing instead. However
it's outsourced into a PECL extension and since Joe cannot install
extensions into the production server he is forced to use unset hacks in the
faulty loops to correct the issue. Joe deploys the application again and can
only hope that this was the only loop that triggered the memory problem and
that the application doesn't crash anywhere else when the products table
grows larger.Also even if an application doesn't run out of memory there might be a
serious performance impact from the memory leaked by objects that can't be
collected properly. If an application peaks at 15 MB instead of 25 MB, the
server can run 40% more child threads in parallel.Regards,
~Hannes
The fast development root does seem to have been a little screwed up
recently, but if there is nothing in an extension that requires direct
access to the core and that extension CAN simply be enabled as required,
then pecl is the way to go? We do need the pecl area to be properly included
in the build process with windows builds being created just as they used to
be, but the process is working fine for APC and perhaps the plan should be
to moving some more extensions that are being worked on between PHP releases
into the pecl process? It used to be that many of the extensions I used were
managed in pecl ... and I'd be quite happy if they moved back there. There
is nothing stopping 'Weak References' being added by those who want them ...
but I can't see the point myself when running scripts live.--
Lester Caine - G8HFLContact - http://lsces.co.uk/wiki/?page=**contacthttp://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/**index.php<http://www.firebirdsql.org/index.php
Hannes Landeholm wrote:
Certain function in the application runs a MySQL procedure that updates a
certain complex selection of products in the products database rendering the
currently loaded products in memory obsolete since they might have been
updated.
Then you are caching the wrong data in memory?
Following an update like that one would either have to commit the changes or
rollback. So the data has to be reloaded from the server anyway. You can't rely
on any of the data already loaded.
Joe deploys the application again and can only hope that this was the
only loop that triggered the memory problem and that the application
doesn't crash anywhere else when the products table grows larger.
So you are trying to load lots of unnecessary data from the database through
poor design. Redesign the data so it works properly ... or switch to a database
that handles business logic via triggers properly ;) You should only be
downloading the data you need to look at, leave the volume data on the server.
The majority of my business logic is done in the database (Firebird) and I
simply can't see how I would ever fall into the trap you seem to be creating?
Perhaps I am doing something wrong, but my systems all run multiuser real time
and handle large numbers of records without these sorts of problem.
--
Lester Caine - G8HFL
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php
Hi!
lists or write RFC's or learn C or jump trough endless hoops in a
process designed so that the core development team can ignore the
community more democratically. The users that just suck it up and
design their applications or frameworks poorly instead because they
don't have time.
I notice some tone of hostility here. Please understand that while your
problem seems to you the most important thing missing in the language,
and maybe for you it is, PHP has millions of users, which need stable
and predictable environment. Which means relying on your or my personal
opinion about some matter is a dangerous thing as it can influence how
millions of people work. This is why we tend to be careful with adding
stuff to the language, especially stuff that has potential long-term
consequences, most of which we don't even know about until this thing
has been tried in the field.
Also, it is very hard to substantially change stuff in the core once
it's there as we have to preserve BC.
This is why we tend to recommend to try the code outside the core if
possible before taking it in.
I'm not sure how to respond to that. "The more I look at it" does not
parse as an actual argument of anything in my head. Be more specific.I strongly disagree that Weak References should be buried in a PECL
You seem to regard PECL as some kind of place where code goes to die.
This is not so. Of course, some PECL extensions do wither and die of
neglect, but others work just fine and have large user base - such as
memcache support, apc, etc. Recommendation of PECL is not a punishment
or disregard for your ideas or code - it is a recognition of the fact
that not every new idea should immediately be implemented in the core.
Also I'm not sure what you expect when you say that it "reached more
maturity". To what end? A feature doesn't really get much more well
defined and simple than this. It's like the whole "it's a single class
If you think all proposals are more complex than this, you are obviously
wrong. Most of recently added things into 5.4 in fact are conceptually
simpler.
simplicity. Unfortunately I don't have time to wait for years even if
many of you guys do. If I did I wouldn't have bothered writing the RFC
or writing in this mailing list. You guys should look into this new
rapid release cycle thing. It's the next iteration of software
development.
Rapid release cycle doesn't mean that we immediately put into the
release everything that was proposed up to the last second when it's
supposed to be released.
If you need a solution for your use cases, I don't see how PECL
extension wouldn't be fine. If you're looking for something which would
run on shared hosting, many shared hosts wouldn't support 5.4 for a long
time even after it's released. Also, I am sure there are ways to
implement the same ideas without this specific class (indirection can be
one idea that may work - it's in fact what PHP does internally with
objects). It may not be the best way, but I think it's doable.
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
Hello Stas,
On 3 August 2011 02:39, Stas Malyshev smalyshev@sugarcrm.com wrote:>
I notice some tone of hostility here.
I'm not hostile. Perhaps a bit disappointed that the PECL objection
wasn't brought up earlier in the discussion period so It could have
been toughly discussed.
/* snip */
This is why we tend to recommend to try the code outside the core if
possible before taking it in.
Yes, this is self evident.
You seem to regard PECL as some kind of place where code goes to die. This
is not so. Of course, some PECL extensions do wither and die of neglect, but
others work just fine and have large user base - such as memcache support,
apc, etc. Recommendation of PECL is not a punishment or disregard for your
ideas or code - it is a recognition of the fact that not every new idea
should immediately be implemented in the core.
See the first paragraph in my previous post.
If you think all proposals are more complex than this, you are obviously
wrong. Most of recently added things into 5.4 in fact are conceptually
simpler.
Weak Reference: An object reference that does not prevent GC. I can't
imagine something more conceptually simple although the use cases are
not very simple. I don't think it's obvious why I am "obviously
wrong".
Rapid release cycle doesn't mean that we immediately put into the release
everything that was proposed up to the last second when it's supposed to be
released.
I'm referring to the fact that PHP has a major update once a year.
Looking at it from an agile perspective this is insanely slow. I think
you should use smaller iterations and release faster. The new Mozilla
release schedule is a good example.
If you need a solution for your use cases, I don't see how PECL extension wouldn't be fine.
I have no problem compiling extensions and I also don't have any
customers on share hosting. Although it wastes a bit more of my time
I'm personally fine with PECL. I'm contributing to open source though
so I'm concerned with the users that won't be able to run my code
because they can't install PECL extensions. I'm also worried that it
will takes years for WR to be moved to the core and that nobody will
notice or use it. PHP deserves weak references. Not in a year but
today.
~Hannes
Hi!
I'm referring to the fact that PHP has a major update once a year.
Looking at it from an agile perspective this is insanely slow. I think
you should use smaller iterations and release faster. The new Mozilla
release schedule is a good example.
Having major changes more frequent would mean people that use PHP would
be forced to constantly update their systems to keep up - or would not
use most of the new features. It would also mean most of new releases
will be unstable for most of their lifecycle - as once they'd stabilize
we'd have new version on the way. And we'd need massive quantity of
resources to test and fix those.
Just for perspective - we have a lot of PHP 4 code still out there and
many still run 5.1. Most projects still can't afford not to have 5.2
support - even though this version is officially dead. Now let's suppose
we are "agile" and have 3 versions in a year. That means developers
would have to test on 6 or 9 versions of PHP instead of 2 or 3 now. Or
people would just ignore all new stuff - and what's the point then?
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
I have no problem compiling extensions and I also don't have any
customers on share hosting. Although it wastes a bit more of my time
I'm personally fine with PECL. I'm contributing to open source though
so I'm concerned with the users that won't be able to run my code
because they can't install PECL extensions. I'm also worried that it
will takes years for WR to be moved to the core and that nobody will
notice or use it. PHP deserves weak references. Not in a year but
today.
Honestly, pecl is kind of self-selecting. APC is installed on millions
of servers and it lives in pecl. It is installed everywhere because it
is an extremely useful extension and distros tend to package it up
promptly for that reason as well. If weak references is a highly
desirable feature that will make every complex framework use less
memory, then I don't see why it wouldn't follow APC's path and end up on
millions of servers.
Note also that there are distros that unbundle core extensions and move
them into separate packages which makes them indistinguishable from pecl
extensions as far as the user is concerned. Realistically, very few end
users are installing from the php.net sources. Just about everyone
installs their distro's version of PHP with whatever extensions the
distro maintainer has decided to include by default.
The major frameworks/CMS systems are also packaged up and carry along
dependencies which sometimes includes extension packages. So again, the
line between core and pecl is very fuzzy here since you could easily
have your framework have a dependency on a pecl extension.
And the final point is that large shared hosting farms is kind of old
fashioned these days. Modern hosting is done with dedicated machine
slices, but there are of course a lot of these legacy shared hosting
farms around. But, given these are legacy systems they are not likely to
rush to upgrade to 5.4 and by the time 5.4 becomes prevalent how many
users are really still going to be on a shared web server config?
I think the only valid point for putting this in core is that it does
feel more like a core feature than a pecl add-on. However, a number of
us are uncomfortable with the impact of it and would like to understand
better how people other than yourself would use it, or more likely,
mis-use it.
-Rasmus
Rasmus Lerdorf wrote:
I think the only valid point for putting this in core is that it does
feel more like a core feature than a pecl add-on. However, a number of
us are uncomfortable with the impact of it and would like to understand
better how people other than yourself would use it, or more likely,
mis-use it.
I think this is were I am sitting at the moment ... If a script needs to tidy up
memory because something has gone wrong, then in my book the script is faulty?
The example of why it is needed does not make sense to me, probably because I
don't understand it, firing an action on the database end and trying to then
simply tidy up the the php end cache without a clean reload just seems wrong?
How do you know what the stored procedure/trigger/business logic has done to the
underlying data? But I've never used MySQL :)
--
Lester Caine - G8HFL
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php
Am 03.08.2011 09:35, schrieb Lester Caine:
I think this is were I am sitting at the moment ... If a script needs to
tidy up memory because something has gone wrong, then in my book the
script is faulty? The example of why it is needed does not make sense to
me, probably because I don't understand it, firing an action on the
database end and trying to then simply tidy up the the php end cache
without a clean reload just seems wrong? How do you know what the stored
procedure/trigger/business logic has done to the underlying data? But
I've never used MySQL :)
I think you might have misunderstood the use case Hannes mentioned. It
is a valid problem and weak references are a neat and indeed the only
clean solution (so far) to it. I ran into similar Problems and it costs
a lot of code and bugfixing to work around the problem, both with the
observer-pattern and object-mapper-cache. Do not ridicule his strategy
just because you've never run into the problem.
Hello,
We had a healthy discussion around WR and I have been able to express
my concerns. The consensus is clearly to put it in a PECL extension so
I think this discussion should move on to the practical matters of
doing this. I suggest aborting the vote and changing the RFC state to
something like "Transfered to PECL".
~Hannes
hi Hannes,
I would suggest to still update the RFC with the various very
instructive comments and example use cases you use in this thread.
Doing the same in the long run should help as well to understand the
goals, implementations, etc., for the pecl users or for the 2nd
attempt to get it in the core, if still desired.
Cheers,
Hello,
We had a healthy discussion around WR and I have been able to express
my concerns. The consensus is clearly to put it in a PECL extension so
I think this discussion should move on to the practical matters of
doing this. I suggest aborting the vote and changing the RFC state to
something like "Transfered to PECL".~Hannes
--
--
Pierre
@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
Good idea. I will see what I can do when I get time.
~Hannes
hi Hannes,
I would suggest to still update the RFC with the various very
instructive comments and example use cases you use in this thread.
Doing the same in the long run should help as well to understand the
goals, implementations, etc., for the pecl users or for the 2nd
attempt to get it in the core, if still desired.Cheers,
Hello,
We had a healthy discussion around WR and I have been able to express
my concerns. The consensus is clearly to put it in a PECL extension so
I think this discussion should move on to the practical matters of
doing this. I suggest aborting the vote and changing the RFC state to
something like "Transfered to PECL".~Hannes
--
--
Pierre@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
Hi,
http://pecl.php.net/package/Weakref has been created, and the
standalone code should compile fine (I checked for 5_3 only but
everything should be smooth for 5_4/trunk)
The next planned addition is a StrongRef class, following the exact
same interface as WeakRef only that it is always valid and get()
always return the ref. The reason for it is that code can switch
between the two transparently.
Best,
Good idea. I will see what I can do when I get time.
~Hannes
hi Hannes,
I would suggest to still update the RFC with the various very
instructive comments and example use cases you use in this thread.
Doing the same in the long run should help as well to understand the
goals, implementations, etc., for the pecl users or for the 2nd
attempt to get it in the core, if still desired.Cheers,
Hello,
We had a healthy discussion around WR and I have been able to express
my concerns. The consensus is clearly to put it in a PECL extension so
I think this discussion should move on to the practical matters of
doing this. I suggest aborting the vote and changing the RFC state to
something like "Transfered to PECL".~Hannes
--
--
Pierre@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
--
--
Etienne Kneuss
http://www.colder.ch
Em Wed, 03 Aug 2011 15:29:20 +0100, Etienne Kneuss colder@php.net
escreveu:
Hi,
http://pecl.php.net/package/Weakref has been created, and the
standalone code should compile fine (I checked for 5_3 only but
everything should be smooth for 5_4/trunk)The next planned addition is a StrongRef class, following the exact
same interface as WeakRef only that it is always valid and get()
always return the ref. The reason for it is that code can switch
between the two transparently.
Wouldn't it be better to have both classes implement a common interface
then?
--
Gustavo Lopes
Hi,
Em Wed, 03 Aug 2011 15:29:20 +0100, Etienne Kneuss colder@php.net
escreveu:Hi,
http://pecl.php.net/package/Weakref has been created, and the
standalone code should compile fine (I checked for 5_3 only but
everything should be smooth for 5_4/trunk)The next planned addition is a StrongRef class, following the exact
same interface as WeakRef only that it is always valid and get()
always return the ref. The reason for it is that code can switch
between the two transparently.Wouldn't it be better to have both classes implement a common interface
then?
Sure
--
Gustavo Lopes--
--
Etienne Kneuss
http://www.colder.ch
Hi,
http://pecl.php.net/package/Weakref has been created, and the
standalone code should compile fine (I checked for 5_3 only but
everything should be smooth for 5_4/trunk)
Not exactly (for the record here):
weakref.c
g:\php-sdk\php54\vc9\x86\pecl\weakref\weakref.c(153) : error C2039:
'default_properties' : is not a member of '_zend_class_entry'
g:\php-sdk\php54\vc9\x86\php54\zend\zend.h(462) : see
declaration of '_zend_class_entry'
g:\php-sdk\php54\vc9\x86\pecl\weakref\weakref.c(153) : warning C4047:
'function' : 'HashTable *' differs in levels of indirection from
'copy_ctor_func_t'
g:\php-sdk\php54\vc9\x86\pecl\weakref\weakref.c(153) : warning C4024:
'zend_hash_copy' : different types for formal and actual parameter 2
g:\php-sdk\php54\vc9\x86\pecl\weakref\weakref.c(153) : warning C4022:
'zend_hash_copy' : pointer mismatch for actual parameter 4
g:\php-sdk\php54\vc9\x86\pecl\weakref\weakref.c(153) : error C2198:
'zend_hash_copy' : too few arguments for call
Cheers,
Pierre
@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
Thanks Etienne,
I was waiting for this for a while! I wrote a blog post how to get
best benefits from weak references:
http://blog.juzna.cz/2011/08/weak-references-in-php/
Perhaps this will help showing people what are they good for.
And thanks to PECL extension I hope we can start using them in my
company very soon in our extension of Zend_Db.
Jan Dolecek
juzna.cz@gmail.com
Hi,
http://pecl.php.net/package/Weakref has been created, and the
standalone code should compile fine (I checked for 5_3 only but
everything should be smooth for 5_4/trunk)The next planned addition is a StrongRef class, following the exact
same interface as WeakRef only that it is always valid and get()
always return the ref. The reason for it is that code can switch
between the two transparently.Best,
Good idea. I will see what I can do when I get time.
~Hannes
hi Hannes,
I would suggest to still update the RFC with the various very
instructive comments and example use cases you use in this thread.
Doing the same in the long run should help as well to understand the
goals, implementations, etc., for the pecl users or for the 2nd
attempt to get it in the core, if still desired.Cheers,
Hello,
We had a healthy discussion around WR and I have been able to express
my concerns. The consensus is clearly to put it in a PECL extension so
I think this discussion should move on to the practical matters of
doing this. I suggest aborting the vote and changing the RFC state to
something like "Transfered to PECL".~Hannes
--
--
Pierre@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
--
--
Etienne Kneuss
http://www.colder.ch
Jan Dolecek wrote:
I was waiting for this for a while! I wrote a blog post how to get
best benefits from weak references:
http://blog.juzna.cz/2011/08/weak-references-in-php/
Perhaps this will help showing people what are they good for.
This again relates to MySQl's method of working ...
ibase_query already has the data in memory before the ibase_fetch_object pulls
it out. In fact you can simply look at the raw data if you want, so I still
don't see how WeakRef would work with interbase/firebird, and I beleive that
postgres and oracle drivers also work the same way? How would xxx_query know
that it is only pulling a single result? In ADOdb we have functions specifically
designed to getOne() but these cache the underlying data until a new call is made?
Or is this simply related to copying the data again from the underlying engine?
--
Lester Caine - G8HFL
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php
Jan Dolecek wrote:
I was waiting for this for a while! I wrote a blog post how to get
best benefits from weak references:
http://blog.juzna.cz/2011/08/weak-references-in-php/
Perhaps this will help showing people what are they good for.
Or you can use various caching algorithms (LRU, MRU, ..) to reduce memory usage:
$this->cache = new ArrayLimit(2);
$this->cache->add(new LargeObject('A'));
$this->cache->add(new LargeObject('B'));
$this->cache->add(new LargeObject('C'));
$this->cache->count(); // 2
To solve a "caching problem" weak references aren't very helpful since there's no way to know when or which objects will be garbage collected (non-deterministic).
Jan Dolecek wrote:
I was waiting for this for a while! I wrote a blog post how to get
best benefits from weak references:
http://blog.juzna.cz/2011/08/weak-references-in-php/
Perhaps this will help showing people what are they good for.Or you can use various caching algorithms (LRU, MRU, ..) to reduce memory usage:
$this->cache = new ArrayLimit(2);
$this->cache->add(new LargeObject('A'));
$this->cache->add(new LargeObject('B'));
$this->cache->add(new LargeObject('C'));
$this->cache->count(); // 2To solve a "caching problem" weak references aren't very helpful since there's no way to know when or which objects will be garbage collected (non-deterministic).
almost every caching mechanism is non-deterministic, so obviously that
isn't a problem for a cache.
a cache is a cache, because you can regenerate its content anytime, if needed.
--
Ferenc Kovács
@Tyr43l - http://tyrael.hu
Hi!
Thanks Etienne,
I was waiting for this for a while! I wrote a blog post how to get
best benefits from weak references:
http://blog.juzna.cz/2011/08/weak-references-in-php/
Perhaps this will help showing people what are they good for.
I'm not sure I understand why you need week refs there - can't you just
always use $prodDb->getProduct(1) and when you don't need it anymore
just do $prodDb->drop(1)? Or let it drop it whenever it wants to?
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
Am 04.08.2011 02:32, schrieb Stas Malyshev:
I'm not sure I understand why you need week refs there - can't you just
always use $prodDb->getProduct(1) and when you don't need it anymore
just do $prodDb->drop(1)? Or let it drop it whenever it wants to?
My Project requires lots of DB-Record <=> PHP-Object mapping, as the
objects get used quite dynamically I can't know when and how often an
object will be used. To make sure there's only one instance of an Object
in Memory per Session, I cache them in an associative-array, the key
being the record-id (actually a PHP-Object consists of many records).
Then I am using the Singleton-Pattern like Library::getObject($id) which
returns a new (fetched freshly from the DB) or an already used object
(from the cache). This works very well and keeps me from expensively
reconstructing objects from the DB. What it does not work well with is
Garbage collection, since the an object will always be referenced at
least once (by the cache). The longer a script is running, the higher
the chance that it will run out of memory (fast). I do want to keep
those objects for as long as possible, but not if the price is an "out
of memory" fatal error.
My solution to this was neither nice nor correct, but I could not think
of anything else: Whenever I'd create a fresh object I'd check memory
against its limit and if it runs close, I will discard the oldest
objects from the cache, always running the risk that my singleton is
suddenly not so single anymore, because a discarded object was still
referenced somewhere else.
So either I get to know if the object is actually in use somewhere else
than just the cache (using the zval-refcount method) or PHP provides me
with something like WeakReference or even better: SoftReference, which
would give me more control as to when it would be collected.
I am open to any suggestions how I could solve my problem without
WeakReference or zval-refcount (short of keeping a ref-count in userland).
Hi!
(from the cache). This works very well and keeps me from expensively
reconstructing objects from the DB. What it does not work well with is
Garbage collection, since the an object will always be referenced at
least once (by the cache). The longer a script is running, the higher
I'm sorry but you putting forth contradictory requirements here - you
want to keep the objects (to avoid "expensively reconstructing" them)
and you don't want to keep them (memory problems). You'll have to give
up one of these requirements. As I see, you gave up the caching
requirement and you clean up objects when memory is tight. As long as
you don't need more objects than you have memory you should be fine.
objects from the cache, always running the risk that my singleton is
suddenly not so single anymore, because a discarded object was still
referenced somewhere else.
You should control your code so that "somewhere else" does not keep
extra references. As well as you'd have to control you code if you use
weak refs, otherwise extra references would still keep objects alive -
or you'd have to rewrite your code and control it so that is always uses
weak refs and always checks that the ref is alive.
I am open to any suggestions how I could solve my problem without
WeakReference or zval-refcount (short of keeping a ref-count in userland).
Do not keep object references, keep object IDs. This would make your
code a bit more verbose and a bit slower, but weak refs would
essentially do the same anyway.
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
Stas Malyshev wrote:
I am open to any suggestions how I could solve my problem without
WeakReference or zval-refcount (short of keeping a ref-count in
userland).Do not keep object references, keep object IDs. This would make your
code a bit more verbose and a bit slower, but weak refs would
essentially do the same anyway.
Like you Stas I am having trouble understanding what the problem is ...
On one 'project' I'm playing with I build a tree of genealogical references in
memory, all identified by their unique_id. If the person has already been
loaded, then it simply uses the existing reference for that element of the tree.
If there is a change to data for some reason the 'cached' record is deleted so
that it has to be re-read from the database next time it's accessed ... if it is
accessed at all. Persons are all class objects ... so deleting is just marking
the object as invalid at which point ( I hope ) the underlying data is dropped.
--
Lester Caine - G8HFL
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php
Stas Malyshev wrote:
I am open to any suggestions how I could solve my problem without
WeakReference or zval-refcount (short of keeping a ref-count in
userland).Do not keep object references, keep object IDs. This would make your
code a bit more verbose and a bit slower, but weak refs would
essentially do the same anyway.Like you Stas I am having trouble understanding what the problem is ...
On one 'project' I'm playing with I build a tree of genealogical references
in memory, all identified by their unique_id. If the person has already been
loaded, then it simply uses the existing reference for that element of the
tree. If there is a change to data for some reason the 'cached' record is
deleted so that it has to be re-read from the database next time it's
accessed ... if it is accessed at all. Persons are all class objects ... so
deleting is just marking the object as invalid at which point ( I hope ) the
underlying data is dropped.
if you have gc enabled, and noone else references that object, then it
will be freed next time when the gc runs.
what weak references are trying to solve, that if you create such a
Registry, as you do, your object will always have at least one
reference (your Registry holds them), so gc won't collect those.
with weak references, you can lazy load your Person records as you do,
but every People record which only referenced through Weakrefs will be
garbage collected on the next gc run.
collecting the garbage will happen if the gc root buffer is full, or
if you manually call gc_collect_cycles.
http://www.php.net/manual/en/features.gc.collecting-cycles.php
--
Ferenc Kovács
@Tyr43l - http://tyrael.hu
Am 04.08.2011 09:17, schrieb Stas Malyshev:
I'm sorry but you putting forth contradictory requirements here - you
want to keep the objects (to avoid "expensively reconstructing" them)
and you don't want to keep them (memory problems). You'll have to give
up one of these requirements. As I see, you gave up the caching
requirement and you clean up objects when memory is tight. As long as
you don't need more objects than you have memory you should be fine.
As long as memory is infinite I'd be fine. It's not contradictory at
all. I have to balance performance gain (keeping objects in memory) and
memory usage (keeping too many objects out of memory).
You should control your code so that "somewhere else" does not keep
extra references. As well as you'd have to control you code if you use
weak refs, otherwise extra references would still keep objects alive -
or you'd have to rewrite your code and control it so that is always uses
weak refs and always checks that the ref is alive.
Not true. With WeakReferences, objects would be cleaned from memory as
soon as my cache-list is the only place left still referencing it and
the GC is run. Even better would be SoftReferences, which would only be
cleaned when there is no memory left.
Do not keep object references, keep object IDs. This would make your
code a bit more verbose and a bit slower, but weak refs would
essentially do the same anyway.
This is like saying: do not use objects at all and use the DB for
storage. verbosity and slowness is something I'd like to prevent.
I did not mean to defend WeakReferences, I just meant to give a valid
use case. Your saying that I shouldn't do it doesn't help much.
Hi!
Do not keep object references, keep object IDs. This would make your
code a bit more verbose and a bit slower, but weak refs would
essentially do the same anyway.This is like saying: do not use objects at all and use the DB for
storage. verbosity and slowness is something I'd like to prevent.
No, it's not even remotely like that. Using one intermediary function
and doing the DB call is orders of magnitude apart. You asked how you
can solve the problem, I showed you how. You can claim you don't like
the solution, that's fine, everybody has his own taste. But you can't
claim there's no other solution.
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
Am 04.08.2011 18:35, schrieb Stas Malyshev:
No, it's not even remotely like that. Using one intermediary function
and doing the DB call is orders of magnitude apart. You asked how you
can solve the problem, I showed you how. You can claim you don't like
the solution, that's fine, everybody has his own taste. But you can't
claim there's no other solution.
Right. I don't like doing design-stuff how they do it in java either,
but a little bit of it hasn't hurt anybody, and it's conciseness helps
readability alot.
I am sure you understand the problem quite well but it's not one of
yours, obviously. That's fine too. But you can't claim the use-case is
not valid.
Hi!
Do not keep object references, keep object IDs. This would make your
code a bit more verbose and a bit slower, but weak refs would
essentially do the same anyway.This is like saying: do not use objects at all and use the DB for
storage. verbosity and slowness is something I'd like to prevent.No, it's not even remotely like that. Using one intermediary function and
doing the DB call is orders of magnitude apart. You asked how you can solve
the problem, I showed you how. You can claim you don't like the solution,
that's fine, everybody has his own taste. But you can't claim there's no
other solution.
maybe it's just me, but I not fully understand your solution.
"I'm not sure I understand why you need week refs there - can't you
just always use $prodDb->getProduct(1) and when you don't need it
anymore just do $prodDb->drop(1)? Or let it drop it whenever it wants
to?"
"Do not keep object references, keep object IDs. This would make your
code a bit more verbose and a bit slower, but weak refs would
essentially do the same anyway."
from that, my guess is that you propose that nobody should hold a
reference for the product, but always use the returned object from
getProduct() on the fly.
you also suggest that ProductDatabase should also remove the cached
object when appropriate.
did I get interpreted your solution correctly?
I have some problems with this approach:
- you cannot guarantee/force the contract that the result of the
getProduct cannot be stored. - in a loosely coupled system, it is hard to tell when "you don't need
it anymore".
as you and Lars both mentioned we only care about freeing the cache,
because we have memory constraint.
Lars mentioned that currently he manually checks the memory usage, and
free the cache if needed:
internals@lists.php.net/msg52423.html" rel="nofollow" target="_blank">http://www.mail-archive.com/internals@lists.php.net/msg52423.html
of course one could also write some algorithm, which removes records
from the cache either randomly, or as Jonathan suggestion doing
something like LRU/MRU.
with Weak References, you shouldn't care about that, the gc would do
it for your, albeit in a less sophisticated way: if the gc root buffer
is full, then free every item which isn't used at that time.
and of course you can combine the WeakRefs and some cache algorithm as
Jan did in his blogpost. (good article btw. and also good to see that
Benjamin Eberlei from the Doctrine project looking into the possible
use cases for them)
so as I see you didn't really addressed the proposed use-case of the
Weak References, just stated what everybody is aware of: one can cache
and free objects "manually" without the need of Weak References.
and while that is true, I still think that this could be a great asset
for creating high quality components.
as we agreed that this won't be considered for inclusion to the core
but released as a pecl extension, I think that we should update the
RFC accordingly and close the vote.
we will see what happens when people start using and experimenting with it.
btw. it was suggested before, but I really think, that it would be a
good idea to have a register_ function which would allow you to pass a
callable, which will be called when the memory usage reaches a given
value.
that would make a good addition to resolve some of use cases mentioned
in this thread.
--
Ferenc Kovács
@Tyr43l - http://tyrael.hu
Hello,
so as I see you didn't really addressed the proposed use-case of the
Weak References, just stated what everybody is aware of: one can cache
and free objects "manually" without the need of Weak References.
and while that is true, I still think that this could be a great asset
for creating high quality components.
I myself oppose WeakReference in java and I do not see my opinion
changing for PHP ... unfortunately I think WeakReference's are even
nastier in PHP because of it's error handling. You see it is very
common when weak references are used in java too follow one of two
paradigms, fall through with NPE's, or state/null checks. With PHP,
you may not "test" the validity of a weak reference simply by
accessing it, you will get a uncatchable fatal error. So in PHP your
only option when consumers are obtaining weak reference handles, is to
check their validity before use, whether that is a call into some
registry, or a null check of the reference itself, whatever.. it still
leads to checks to make sure that reference wasn't collected. This
added complexity in the WeakReference consumer makes me unable see any
purpose through the inconvenience and unpredictability they bring.
btw. it was suggested before, but I really think, that it would be a
good idea to have a register_ function which would allow you to pass a
callable, which will be called when the memory usage reaches a given
value.
that would make a good addition to resolve some of use cases mentioned
in this thread.
I use ticks to do this in a CLI daemon I wrote, worked out pretty
well. Not saying a specialized function isn't needed but I think ticks
aren't to far from convenient to require such.
Am 04.08.2011 23:19, schrieb Chris Stockton:
I myself oppose WeakReference in java and I do not see my opinion
changing for PHP ... unfortunately I think WeakReference's are even
nastier in PHP because of it's error handling. You see it is very
common when weak references are used in java too follow one of two
paradigms, fall through with NPE's, or state/null checks. With PHP,
you may not "test" the validity of a weak reference simply by
accessing it, you will get a uncatchable fatal error. So in PHP your
only option when consumers are obtaining weak reference handles, is to
check their validity before use, whether that is a call into some
registry, or a null check of the reference itself, whatever.. it still
leads to checks to make sure that reference wasn't collected. This
added complexity in the WeakReference consumer makes me unable see any
purpose through the inconvenience and unpredictability they bring.
Though I have never used java, I believe Weak- and SoftReferences would
tremendously simplify certain, very specific applications.
-
WeakReferences for implementing the observer pattern
aka. keeping a list of handlers for certain events. -
SoftReferences for caching
aka. keeping a list of objects to be returned or created by a factory
If used this way, there is no danger of null-fatal-errors, because the
event-trigger is aware of the volatile nature of its handlers and the
factory knows that it's cached objects might be discarded.
In fact, I'd say that Weak-/Soft-References are a better fit in PHP than
in Java, because the ->get() methods return type is non-specific (has to
be cast in java?)...which matches PHPs untyped approach.
I use ticks to do this in a CLI daemon I wrote, worked out pretty
well. Not saying a specialized function isn't needed but I think ticks
aren't to far from convenient to require such.
Could you explain ticks?...to me a tick is a nasty little creature that
bites and gives you infections;)
Could you explain ticks?...to me a tick is a nasty little creature that
bites and gives you infections;)
Ticks have been in PHP forever. See
http://www.php.net/manual/en/control-structures.declare.php#control-structures.declare.ticks
-Rasmus
Am 05.08.2011 08:07, schrieb Rasmus Lerdorf:
Ticks have been in PHP forever. See
http://www.php.net/manual/en/control-structures.declare.php#control-structures.declare.ticks
woha! interesting read. thanks:)
Hi!
Do not keep object references, keep object IDs. This would make your
code a bit more verbose and a bit slower, but weak refs would
essentially do the same anyway.This is like saying: do not use objects at all and use the DB for
storage. verbosity and slowness is something I'd like to prevent.No, it's not even remotely like that. Using one intermediary function and
doing the DB call is orders of magnitude apart. You asked how you can solve
the problem, I showed you how. You can claim you don't like the solution,
that's fine, everybody has his own taste. But you can't claim there's no
other solution.maybe it's just me, but I not fully understand your solution.
"I'm not sure I understand why you need week refs there - can't you
just always use $prodDb->getProduct(1) and when you don't need it
anymore just do $prodDb->drop(1)? Or let it drop it whenever it wants
to?"
"Do not keep object references, keep object IDs. This would make your
code a bit more verbose and a bit slower, but weak refs would
essentially do the same anyway."from that, my guess is that you propose that nobody should hold a
reference for the product, but always use the returned object from
getProduct() on the fly.
you also suggest that ProductDatabase should also remove the cached
object when appropriate.
did I get interpreted your solution correctly?I have some problems with this approach:
- you cannot guarantee/force the contract that the result of the
getProduct cannot be stored.- in a loosely coupled system, it is hard to tell when "you don't need
it anymore".
as you and Lars both mentioned we only care about freeing the cache,
because we have memory constraint.
Lars mentioned that currently he manually checks the memory usage, and
free the cache if needed:
internals@lists.php.net/msg52423.html" rel="nofollow" target="_blank">http://www.mail-archive.com/internals@lists.php.net/msg52423.html
of course one could also write some algorithm, which removes records
from the cache either randomly, or as Jonathan suggestion doing
something like LRU/MRU.
with Weak References, you shouldn't care about that, the gc would do
it for your, albeit in a less sophisticated way: if the gc root buffer
is full, then free every item which isn't used at that time.
and of course you can combine the WeakRefs and some cache algorithm as
Jan did in his blogpost. (good article btw. and also good to see that
Benjamin Eberlei from the Doctrine project looking into the possible
use cases for them)so as I see you didn't really addressed the proposed use-case of the
Weak References, just stated what everybody is aware of: one can cache
and free objects "manually" without the need of Weak References.
and while that is true, I still think that this could be a great asset
for creating high quality components.
To make sure I understand the advantages of weak references paired with
caching, this is what I understand:
- While in the size-limited cache, an object would never be garbage-collected.
- If the size-limited cache decides to prune an object, and the
object is still
being referenced in a variable, the weak reference map will allow you to avoid
making a call to the db, and avoid having a duplicate object. - If the size-limited cache decides to prune an object, and the object is not
referenced anywhere, the object may be gc'ed at any time, meaning the weak
reference may not be valid(). However, there may be some time between
garbage collection that the object is still available if the code
requests a new
instance of the object. This behavior could not be relied on, but might avoid
some small amount of traffic to the db.
So the advantage is mostly in case 2, where we avoid the duplication of an
object. For example, in code like this(which is obviously silly, but
given a more
complex application might happen):
function foo() {
$bar = Bar::get(1);
$bar->baz = 2
anotherFoo();
$bar->save();
}
function anotherFoo() {
$bar = Bar::get(1);
$bar->baz = 4;
$bar->save();
}
If the cache pruned the Bar object with id 1 before anotherFoo() was
called, without
weak references, we would have two different $bar objects. With weak
references,
they still refer to the same object.
Are there other advantages I'm missing?
If not, I see some advantage to Weak References, but I'm glad to be
playing with
them in PECL to see exactly how much real advantage they would give.
Thanks,
John
Am 05.08.2011 14:58, schrieb John LeSueur:
Are there other advantages I'm missing?
If I may, I'll respond to your questions with 3 examples.
A) Naive, straight forward approach (this will run out of memory if
objects are heavy)
http://pastie.org/2325252
B) Previous approach taking memory into consideration:
http://pastie.org/2325317
C) Clean, memory efficient approach using SoftReferences
http://pastie.org/2325254
The Problem with B) is that depending on how I use the objects, I am
dropping objects from cache (to free memory) that are still in use. If I
then re-add them to the cache, my singleton-pattern will be broken.
NB: In the simple example I used, this is not a problem because I do not
keep references to more than one object.
Soft references could theoretically be implemented if PHP only implemented
weak references even though the implementation would consist of a very ugly
and "coincidental" hack.
Lets say you had an object A that you wouldn't want to be collected until
approximately when PHP needs more memory. E.g. we want to implement some
sort of caching behavior. Note the difference towards weak references which
allows objects to be collected directly when they are not strongly
referenced anymore. In the caching scenario we don't know weather the object
might be used again so we want it to be retained in memory as long as it's
not a problem - e.g. as long as PHP doesn't use "too much" memory.
Now after object A is created we create a weak reference for it in our
cache. Then we create another object B which is just a StdClass with a
single field "ptr" which is a strong reference to A. Then we create a strong
reference from A to B and so a cyclic reference memory structure is born. A
(and B) will now be unable to be garbage collected until gc_collect_cycles
runs which happens when the "root buffer is full" - piggybacking on PHP's
internal approximation of when enough memory has been allocated that the
probability is high enough for garbage cycle collection to be worth it.
This also assumes that you can add an arbitrary property to the A object
without disrupting it's behavior. Adding arbitrary properties to other
objects violates encapsulation and is generally not good design. Also since
this implementation of a soft reference depends on internal PHP
implementation I would avoid such design though unless careful testing is
made and the behavior is disabled if an incremented PHP version is detected
where there is a possibility that the PHP GC implementation might have
changed.
It's interesting to think about though.
Also I would not rely on "ticks" for anything really except debugging. It's
an unreliable performance killer.
~Hannes
It sounds to me that weak/soft references are only really half a
solution to a problem.
As Chris Stockton points out http://news.php.net/php.internals/54391
there is always going to be additional code that has to check to see if
the reference is still valid.
If the only concern here is running out of memory, surely you could
design a framework that could reduce it's memory usage without having to
get rid of it's objects.
For example, your ORM objects will have a store of data. You could run a
process every now and again that deletes the data from the objects
(everything except the ID of the table). And then write it in to the
framework so that if you start using the object again it goes and gets
it's data back?
Am 05.08.2011 19:46, schrieb Jezz Goodwin:
As Chris Stockton points out http://news.php.net/php.internals/54391
there is always going to be additional code that has to check to see if
the reference is still valid.
But don't you see that in exchange for one little IF you get so much
more...what's an NPE compared to an OOME;)
If the only concern here is running out of memory, surely you could
design a framework that could reduce it's memory usage without having to
get rid of it's objects.
It's not about a framework, it's about making use of what is available
(memory & processing power) and balancing those two....and PHP is not
very efficient with its objects...I might be wrong here, but I think
that because PHP supports dynamic assigning of properties, it addresses
them by name and not as in a c++ object by memory-offset, but I am out
of my depth here, having deduced this without looking at the source-code.
For example, your ORM objects will have a store of data. You could run a
process every now and again that deletes the data from the objects
(everything except the ID of the table). And then write it in to the
framework so that if you start using the object again it goes and gets
it's data back?
Actually my use-case is single-threaded and linear, so I can't really
run a second process...but if this is your solution compared to
SoftReferences with one IF, then I am not sure I like yours better.
Also WeakReferences and SoftReferences are used in completely different
situations. The two concepts are related but not its applications.
I just remembered something I encountered in an AS3 project I
made...it's a perfect example for WeakReferences. (you might not like
AS3 but you may appreciate the fact that it also uses this concept)
================
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/EventDispatcher.html#addEventListener%28%29
public function addEventListener(type:String, listener:Function,
useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean =
false):void
If you no longer need an event listener, remove it by calling
removeEventListener(), or memory problems could result. Event listeners
are not automatically removed from memory because the garbage collector
does not remove the listener as long as the dispatching object exists
(unless the useWeakReference parameter is set to true).
================
Am 05.08.2011 18:29, schrieb Hannes Landeholm:
It's interesting to think about though.
I'd definitely find a use for them;) I might just patch our
installations to provide me with the zval-refcount and go with that for
now...I have been warned, but I have to burn myself before I believe
that boiling water is hot;)
I just thought of another design-pattern which could make use of
WeakReferences...The composite design pattern.
http://en.wikipedia.org/wiki/Composite_pattern
A parent references its childs and each child references its parent.
circular-reference nightmare...with WeakReferences I could use a
weakReference for storing the parent...so that if the parents last real
reference is discarded the childs will cleaned out as well.
A parent references its childs and each child references its parent.
circular-reference nightmare...with WeakReferences I could use a
weakReference for storing the parent...so that if the parents last real
reference is discarded the childs will cleaned out as well.
that is why we added the gc in 5.3, to be able to collect the circular
references, which isn't used outside of their own.
as Etienne pointed out on irc, it seems that some people not really
familiar how php frees the unused variables.
before 5.3, we only used refcounts, if a refcount is decremented to
zero the zval will be freed instantly.
for example calling unset, or overwriting a variable from userland
decrease the refcount for that zval.
but this isn't good enough, as the refcounting couldn't spot and free
the zvals, which wasn't referenced from the userland anymore, only
from other unused zvals, which were also referenced by another unused
zval (either two zval referencing each other, or through a "circle")
this is why the gc mechanism was added in 5.3. the garbage collector
runs periodically, and checks the potential zvals, and finds those
zval "islands" and frees those.
I hope that clears up the mess, and please correct me, if I'm wrong
somewhere in the explanation.
--
Ferenc Kovács
@Tyr43l - http://tyrael.hu
Good explanation Ferenc.
Yeah I think there's a lot of misunderstandings going on with weak/soft
references and how the garbage collector works. Weak/soft references is not
some kind of solution to the cyclic reference problem. The GC takes care of
that already. You can use whatever OOP patterns with whatever reference
graphs you like Lars, the GC will free the entire structure as soon as the
cyclic collector runs after you are not referencing it anymore. You might
have become a bit confused with my last post where I explained how one could
theoretically hack together a soft reference implementation by using weak
references and some properties of cyclic collection. Also property access
performance is off-topic.
- Weak references solves the loose coupled object indexing problem. "I need
this reference as long as it's referenced somewhere else." - Soft references solves the caching problem. "I need this reference as long
as we have plenty of memory available." - The GC solves the cyclic reference problem (since 5.3).
~Hannes
Am 06.08.2011 02:14, schrieb Hannes Landeholm:
Yeah I think there's a lot of misunderstandings going on with weak/soft
references and how the garbage collector works. Weak/soft references is not
some kind of solution to the cyclic reference problem. The GC takes care of
that already. You can use whatever OOP patterns with whatever reference
graphs you like Lars, the GC will free the entire structure as soon as the
cyclic collector runs after you are not referencing it anymore. You might
have become a bit confused with my last post where I explained how one could
theoretically hack together a soft reference implementation by using weak
references and some properties of cyclic collection. Also property access
performance is off-topic.
I did not misunderstand how weak/soft-references or php's new GC works.
Having a GC collect circular references is neat, but if I remember
correctly, collecting them (which is why there are other, faster methods
but which require more memory) is neither simple nor fast (whatever that
means) so...if I can assist the GC by clearly stating that my
child-objects may be collected as soon as they and their parent are not
referenced from userland anymore thus not requiring the GC and thus
freeing memory as soon as possible,...seems like an optimization worth
thinking of. Especially if I tend to have vast structures with hundreds
of objects.
In 5.2 (we can't move our project to 5.3 yet because of a BC issue) i
had to manually clear those cycles before dropping the last userland
reference to the tree of objects because otherwise I'd run into memory
problems when processing alot of those trees.
I have mixed feelings about this proposal - from one point it's quite
neat - ability to mark circular references for the memory manager so
it can free them sounds very delicious, especially for some cases. I
had run into my own bunch of problems with memory in PHP in the past
and right now I'm running a daemon written in PHP in production on
5.3.6. Careful construction and knowledge that circular references
actually do harm I did add safeguards that actually clean up the
objects in recursive manner (and objects have internal flags that
cleanup has been initiated - that way I make sure I cleanup the same
object only once). That sort of planing at the design stage makes it
far more friendly with memory, so it doesn't mean that PHP should have
soft references.
My opinion is that if this can be done without using significant
resources and will not have major issues while implementing - it can
be added, otherwise just skip it - better off fixing bugs and
optimizing :)
2011/8/6 Lars Schultz lars.schultz@toolpark.com:
Am 06.08.2011 02:14, schrieb Hannes Landeholm:
Yeah I think there's a lot of misunderstandings going on with weak/soft
references and how the garbage collector works. Weak/soft references is
not
some kind of solution to the cyclic reference problem. The GC takes care
of
that already. You can use whatever OOP patterns with whatever reference
graphs you like Lars, the GC will free the entire structure as soon as the
cyclic collector runs after you are not referencing it anymore. You might
have become a bit confused with my last post where I explained how one
could
theoretically hack together a soft reference implementation by using weak
references and some properties of cyclic collection. Also property access
performance is off-topic.I did not misunderstand how weak/soft-references or php's new GC works.
Having a GC collect circular references is neat, but if I remember
correctly, collecting them (which is why there are other, faster methods but
which require more memory) is neither simple nor fast (whatever that means)
so...if I can assist the GC by clearly stating that my child-objects may be
collected as soon as they and their parent are not referenced from userland
anymore thus not requiring the GC and thus freeing memory as soon as
possible,...seems like an optimization worth thinking of. Especially if I
tend to have vast structures with hundreds of objects.In 5.2 (we can't move our project to 5.3 yet because of a BC issue) i had to
manually clear those cycles before dropping the last userland reference to
the tree of objects because otherwise I'd run into memory problems when
processing alot of those trees.
Am 09.08.2011 14:22, schrieb Arvids Godjuks:
I have mixed feelings about this proposal - from one point it's quite
neat - ability to mark circular references for the memory manager so
it can free them sounds very delicious, especially for some cases. I
had run into my own bunch of problems with memory in PHP in the past
and right now I'm running a daemon written in PHP in production on
5.3.6. Careful construction and knowledge that circular references
actually do harm I did add safeguards that actually clean up the
objects in recursive manner (and objects have internal flags that
cleanup has been initiated - that way I make sure I cleanup the same
object only once). That sort of planing at the design stage makes it
far more friendly with memory, so it doesn't mean that PHP should have
soft references.
Exactly what I did;)
My opinion is that if this can be done without using significant
resources and will not have major issues while implementing - it can
be added, otherwise just skip it - better off fixing bugs and
optimizing :)
Of course. I am not saying that its a must have...just wanted to defend
it from being marked as useless.
How about adding weak maps to this RFC?
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/WeakMap
This would be fantastic!
Nicolas
On Tue, Aug 9, 2011 at 14:55, Lars Schultz lars.schultz@toolpark.comwrote:
Am 09.08.2011 14:22, schrieb Arvids Godjuks:
I have mixed feelings about this proposal - from one point it's quite
neat - ability to mark circular references for the memory manager so
it can free them sounds very delicious, especially for some cases. I
had run into my own bunch of problems with memory in PHP in the past
and right now I'm running a daemon written in PHP in production on
5.3.6. Careful construction and knowledge that circular references
actually do harm I did add safeguards that actually clean up the
objects in recursive manner (and objects have internal flags that
cleanup has been initiated - that way I make sure I cleanup the same
object only once). That sort of planing at the design stage makes it
far more friendly with memory, so it doesn't mean that PHP should have
soft references.Exactly what I did;)
My opinion is that if this can be done without using significant
resources and will not have major issues while implementing - it can
be added, otherwise just skip it - better off fixing bugs and
optimizing :)Of course. I am not saying that its a must have...just wanted to defend it
from being marked as useless.
Hi,
On Fri, Sep 2, 2011 at 14:25, Nicolas Grekas
nicolas.grekas+php@gmail.comwrote:
How about adding weak maps to this RFC?
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/WeakMap
This would be fantastic!
Nicolas
Indeed, I planned to implement that as well, I haven't had the time to do it
yet though. It should happen in the following weeks.
Best,
On Tue, Aug 9, 2011 at 14:55, Lars Schultz <lars.schultz@toolpark.com
wrote:
Am 09.08.2011 14:22, schrieb Arvids Godjuks:
I have mixed feelings about this proposal - from one point it's quite
neat - ability to mark circular references for the memory manager so
it can free them sounds very delicious, especially for some cases. I
had run into my own bunch of problems with memory in PHP in the past
and right now I'm running a daemon written in PHP in production on
5.3.6. Careful construction and knowledge that circular references
actually do harm I did add safeguards that actually clean up the
objects in recursive manner (and objects have internal flags that
cleanup has been initiated - that way I make sure I cleanup the same
object only once). That sort of planing at the design stage makes it
far more friendly with memory, so it doesn't mean that PHP should have
soft references.Exactly what I did;)
My opinion is that if this can be done without using significant
resources and will not have major issues while implementing - it can
be added, otherwise just skip it - better off fixing bugs and
optimizing :)Of course. I am not saying that its a must have...just wanted to defend
it
from being marked as useless.--
--
Etienne Kneuss
http://www.colder.ch
Am 03.09.2011 13:56, schrieb Etienne Kneuss:
Indeed, I planned to implement that as well, I haven't had the time to do it
yet though. It should happen in the following weeks.
Not to keep you from doing this...but couldn't that easily be solved by
using a simple associative php array like this:
$pseudoWeakMap = array();
$pseudoWeakMap[spl_object_hash($obj)] = new WeakReference($obj);
or did I misunderstand the concept? I hope I'll have a chance to use
WeakReferences soon in my project;)
Hi,
On Sat, Sep 3, 2011 at 17:14, Lars Schultz lars.schultz@toolpark.comwrote:
Am 03.09.2011 13:56, schrieb Etienne Kneuss:
Indeed, I planned to implement that as well, I haven't had the time to do
ityet though. It should happen in the following weeks.
Not to keep you from doing this...but couldn't that easily be solved by
using a simple associative php array like this:$pseudoWeakMap = array();
$pseudoWeakMap[spl_object_**hash($obj)] = new WeakReference($obj);or did I misunderstand the concept? I hope I'll have a chance to use
WeakReferences soon in my project;)
My understanding of weak maps would be a way to associate data with objects,
and have the data be freed once the object itself is deleted.
So basically in example:
$map = new WeakMap;
$obj = new Class;
$map[$obj] = .. some data ..
...
var_dump($map[$obj]); // .. some data ..
unset($obj); // unsets $map[$obj] automatically as well.
var_dump(isset($map[$obj])); // bool(false)
So sure, it could be implemented using spl_object_hash and having the Class
destructor take care of deleting all that associated Data, but using
weakmaps would make it far more convenient.
Best,
--
--
Etienne Kneuss
http://www.colder.ch
$pseudoWeakMap = array();
$pseudoWeakMap[spl_object_**hash($obj)] = new WeakReference($obj);or did I misunderstand the concept? I hope I'll have a chance to use
WeakReferences soon in my project;)
I also believe that this is the logic, but from the doc, when an object is
destroyed, its hash may be reused for other objects.
So this implementation could possibly have bad side effect, isn't it ?
Nicolas
Hi,
On Sat, Sep 3, 2011 at 19:21, Nicolas Grekas
nicolas.grekas+php@gmail.comwrote:
$pseudoWeakMap = array();
$pseudoWeakMap[spl_object_**hash($obj)] = new WeakReference($obj);or did I misunderstand the concept? I hope I'll have a chance to use
WeakReferences soon in my project;)I also believe that this is the logic, but from the doc, when an object is
destroyed, its hash may be reused for other objects.
So this implementation could possibly have bad side effect, isn't it ?Nicolas
I don't understand how the code you just gave would be useful in practice?
I've implemented a WeakMap class in the weakref pecl ext, see:
http://svn.php.net/viewvc/pecl/weakref/trunk/tests/weakmap_001.phpt?revision=316293&view=markup
for an example of usage.
I believe this better fit people's needs. Or did you have something else in
mind?
Best,
--
Etienne Kneuss
http://www.colder.ch
I don't understand how the code you just gave would be useful in practice?
Is that question for me ? If yes, which code are you talking about ?
I've implemented a WeakMap class in the weakref pecl ext, see:
For ref: https://github.com/colder/php-weakref/blob/master/tests/weakmap_001.phpt
I believe this better fit people's needs. Or did you have something else in
mind?
Talking for me, that's cool !
Just one question about the interface :
Javascript interface is based on a setter/getter rather than any kind of
ArrayAccess.
Does anybody has an idea if on this case, about ArrayAccess vs setter/getter
?
For example, wouldn't people expect "foreach" to work when $wm[] access is
possible ?
Personally, I like the current syntax, it's short. I'm just wondering of any
corner case exists?
Nicolas
Hi,
On Fri, Sep 9, 2011 at 10:14, Nicolas Grekas
nicolas.grekas+php@gmail.comwrote:
I don't understand how the code you just gave would be useful in practice?
Is that question for me ? If yes, which code are you talking about ?
$pseudoWeakMap = array();
$pseudoWeakMap[spl_object_**hash($obj)] = new WeakReference($obj);
I've implemented a WeakMap class in the weakref pecl ext, see:
For ref: https://github.com/colder/php-weakref/blob/master/tests/weakmap_001.phpt
I believe this better fit people's needs. Or did you have something else in
mind?
Talking for me, that's cool !
Just one question about the interface :
Javascript interface is based on a setter/getter rather than any kind of
ArrayAccess.
I could easily create a method alias get/set, if needed.
Does anybody has an idea if on this case, about ArrayAccess vs
setter/getter ?
For example, wouldn't people expect "foreach" to work when $wm[] access is
possible ?
Personally, I like the current syntax, it's short. I'm just wondering of
any corner case exists?
I'll probably make it iterable in the future, yes.
Best,
Nicolas
--
Etienne Kneuss
http://www.colder.ch
Hi,
On Tue, Aug 9, 2011 at 14:22, Arvids Godjuks arvids.godjuks@gmail.comwrote:
I have mixed feelings about this proposal - from one point it's quite
neat - ability to mark circular references for the memory manager so
it can free them sounds very delicious, especially for some cases. I
had run into my own bunch of problems with memory in PHP in the past
and right now I'm running a daemon written in PHP in production on
5.3.6. Careful construction and knowledge that circular references
actually do harm I did add safeguards that actually clean up the
objects in recursive manner (and objects have internal flags that
cleanup has been initiated - that way I make sure I cleanup the same
object only once). That sort of planing at the design stage makes it
far more friendly with memory, so it doesn't mean that PHP should have
soft references.My opinion is that if this can be done without using significant
resources and will not have major issues while implementing - it can
be added, otherwise just skip it - better off fixing bugs and
optimizing :)
Weak references have been implemented in a PECL extension since weeks now:
http://php.net/weakref and/or http://pecl.php.net/weakref
It feels like you're beating up a dead horse here.
A discussion for bundling it might occur in the future, but given the
feedbacks PECL might very well be the right place for it.
Best,
2011/8/6 Lars Schultz lars.schultz@toolpark.com:
Am 06.08.2011 02:14, schrieb Hannes Landeholm:
Yeah I think there's a lot of misunderstandings going on with weak/soft
references and how the garbage collector works. Weak/soft references is
not
some kind of solution to the cyclic reference problem. The GC takes care
of
that already. You can use whatever OOP patterns with whatever reference
graphs you like Lars, the GC will free the entire structure as soon as
the
cyclic collector runs after you are not referencing it anymore. You
might
have become a bit confused with my last post where I explained how one
could
theoretically hack together a soft reference implementation by using
weak
references and some properties of cyclic collection. Also property
access
performance is off-topic.I did not misunderstand how weak/soft-references or php's new GC works.
Having a GC collect circular references is neat, but if I remember
correctly, collecting them (which is why there are other, faster methods
but
which require more memory) is neither simple nor fast (whatever that
means)
so...if I can assist the GC by clearly stating that my child-objects may
be
collected as soon as they and their parent are not referenced from
userland
anymore thus not requiring the GC and thus freeing memory as soon as
possible,...seems like an optimization worth thinking of. Especially if I
tend to have vast structures with hundreds of objects.In 5.2 (we can't move our project to 5.3 yet because of a BC issue) i had
to
manually clear those cycles before dropping the last userland reference
to
the tree of objects because otherwise I'd run into memory problems when
processing alot of those trees.--
--
--
Etienne Kneuss
http://www.colder.ch
Weak references have been implemented in a PECL extension since weeks now:
http://php.net/weakref and/or http://pecl.php.net/weakrefIt feels like you're beating up a dead horse here.
A discussion for bundling it might occur in the future, but given the
feedbacks PECL might very well be the right place for it.
that mail was sent on Aug 9.
--
Ferenc Kovács
@Tyr43l - http://tyrael.hu
Weak references have been implemented in a PECL extension since weeks
now:
http://php.net/weakref and/or http://pecl.php.net/weakrefIt feels like you're beating up a dead horse here.
A discussion for bundling it might occur in the future, but given the
feedbacks PECL might very well be the right place for it.that mail was sent on Aug 9.
right :) why did I feel Aug 9 was 2 days ago ? Time flies...
--
Ferenc Kovács
@Tyr43l - http://tyrael.hu
--
Etienne Kneuss
http://www.colder.ch