J
Jean-Hugues ROBERT
Florian Gross said:Jim said:Florian Gross said:
[problems with proxies]
Comparisons are problematic because the first line of a comparison is
often "Are you the same class as me?". Proxies arent't the right class so
the comparisons fail.
It depends -- the answer to that question can be overloaded in most
cases. (Though Object.instance_methodclass).bind(obj).call will
always give you the real class and I think that some of the internal
methods actually do something like that.)
Actually, rather than a become or class= method, I would be interested in
a swap_identitys method. For example, to make a proxy object real ...
def make_real
obj = read_real_object_from_the_database
swap_identities(self, obj)
end
When identities are swapped, every reference in the system to the
first
object will magically become a reference to the second object, and
vice-versa.
This is how Squeak implements this AFAIK -- it just iterates through
all Object references and changes them.
I'm not sure, but this could be a bit slow, maybe. (And I'm not sure
if it would be a general solution for the problems with Proxy objects
-- it would work in the lazy database example, but there might be
other problematic use cases.)
How about changing the object to a redirection pointer, and also
updating references in the garbage collector's root set traversal?
You'd get some overhead at first, but after one garbage collection, all
references will be updated and the redirection object can be recycled.
mikael
OTOH you don't want to make a slow thing even slower and it
is my understanding that current Ruby's GC has enough room
for improvement that a serious re-implementation is in
progress.
I guess the change (removing the additional level for indirection)
could be done when the pointer is checked for redirection.
That stills mean an additional check on every use of a
reference. Which is a lot I guess.
Thoughts: Maybe "become" semantic can be implemented (as already
suggested) with some "proxy" solution. But a highly optimized/
specialized "become" oriented C implementation. As a result,
use of objects that "became" something else would be slightly
slower than use of "normal" objects, but "normal" objects would
keep their current speed. Nota: The "class" of the "become
proxied object" has to be the proper one, to avoid the issue
with proxies involved in comparisons that check classes.
That way, you pay for the feature only when you use it.
Yours,
JeanHuguesRobert