-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split atoms copying and atom creation factory methods and generalize ClassFactory #2024
Comments
I think I like this. But first some general commentary, just so that things are clear.
OK that's the story of factories. The stories of validators are different.
So I think I like your proposal. Some point by point comments:
Sure, fine, don't care.
Uh sure, I guess ?? I'm not sure what this solves.
Yes. I think you discovered this in your unit test. I wrote
OK
Avoid copies, per above.
Careful, I had to fix a bug in ValueFactory just a few weeks ago. It works, I like the idea, but the use of the static is ... interesting, non-obvious, subtle, and error prone.
Uhh, sure I guess. I don't understand what that means. Keep in mind, most atoms should be "empty shells", unborn seeds, just passing through, temporary holders for a type, a node-string and a handle-seq. it should be simple and fast to create them, and then let them die as soon as they've moved thier atom-style-date from the API to the atomspace. |
OK, so here: There a bad bug there. atomspace/opencog/atoms/base/Node.h Lines 128 to 134 in e47dc46
The above is a bug. Apparently, I am the one who added this bug, 16 months ago: 7b70922 I just now tried to fix it and 84 unit tests failed out of 143; most segfaulted. That's just crazy. 17 months ago, things worked fine, so what happened? Yecchhhh. And here: 44b212b It seems that I was trying to remove the factory from the atom table, so that the atom table code would be simpler. But after this change, the "empty shells" are no longer empty. So that was a mistake. This stuff is hard. We don't have any good performance tests to catch these kinds of mistakes. It's also possible that I am making a mountain out of a molehill. Maybe the main performance bottlenecks are in a completely different place... |
This comment: This is a symptom of a general confusion about when to use temporaries/empty-shells, and when one has the "real" atom. Inserting an atom into the atomspace is expensive (its slow, there is lock contention) and so there is a lot of effort made to avoid putting atoms into the atomspace, until we are really sure we want to. As a result, there are a lot of temporaries and "empty shells" floating around. But sometimes, the empty shell is not good enough, because we need to call some method on the "real" c++ class. This results in a lot of hackery and confusion. Maybe the correct long-term fix is that, whenever we need an actual C++ instance, and the |
As I see previous |
Working on PR #2029 I have realized that in case of multiple inheritance (for example NODE_C <- NODE_B, NODE_A) and when both NODE_A and NODE_B have validators then only validator of NODE_B will be called. Should we make a chain of validators calls to run all of type validators not only one? |
Yes, but what I am saying is that createNode and createLink almost surely should not be calling the factory. (?) They should be creating temporary "empty shells". The idea is that the "empty shell" avoids the CPU over-head of calling the ctor. The goal is that the "empty shell" is a small, light-weight, non-functional way to temporarily hold a type, a name-string, an handle-seq for just a little while. |
But I didn't see in code examples when empty shell is created and used before calling factory on it. And from my perspective it makes sense because all that you can do with empty shell is persist it. To call any method on it you need to convert empty shell to the instance of the right class. |
Yes. |
If you get the urge to rename |
I'm not sure either why you'd absolutely need an atomspace to fully instantiate and use an atom. What is the problem with filling the shell before inserting to atomspace? Inserting has a cost, sometimes and you'd rather keep redundant copies and avoid that cost. Well, I guess you can always have an atomspace per copy but that's an overhead. |
OK. It probably doesn't matter, at this time. What I'm trying to say is that if you put a printf into some atom constructor, you will see it print twice: once, when the atom is created outside the atomspace, and once when the private-copy is created. I'm mostly just torturing myself (and torturing you) over this; there is no obvious or easy fix for this, and I should just stop talking. But now you know: most atoms get created twice.
Yes, go ahead and do this. Sorry to have derailed the conversation so much. #2029 looks good. Is everything here now done? |
Hi @ngeiswei
Well, the classic example is banking. If there is one and only one globally-unique atom per bank-account, then you can safely store money in it. But if I have two atoms for one bank account, and I withdraw $500 from one of them, does that mean I still have $500 in the other? For this reason, pretty much all databases since the dawn of time have insisted that atoms are always globally unique; chaos ensues when they are not. That said, there are 1001 exceptions where data does not have to be absolutely, totally unique. |
Not yet, will work on this further |
This issue is to discuss plan of removing unnecessary double atoms creation which were discussed at issue #1965, especially in comments:
At the moment
createNode
andcreateLink
functions create instance of unspecific instance ofNode
orLink
class and passes them intoClassServer::factory
which creates another atoms with proper class.Suggested plan:
DEFINE_LINK_FACTORY
DEFINE_NODE_FACTORY
to theClassFactory::factory
methodvalidating_factory
inClassServer::addValidator
method, just call proper validator instead inClassFactory::factory
ClassServer::spliceFactory
method to splice not only factories but validators as wellClassServer::_copier
collection to keep methods to copy atomscopyAtom
to use it inAtomTable::add
method for atoms copyingHandle (*)(const Handle& )
factory method signature by method with vararg like inValueFactory
createNode
andcreateLink
replace new atom creation by arguments forwardingThe text was updated successfully, but these errors were encountered: