"cloning" a running engine

Hello,

I understand that any goal can be executed by an engine. This means that an engine is created and then the goal called within the engine.

I am wondering, could it be possible to clone a running engine – to generate a new engine with a state of a current engine intact?

One use cases for such a feature is in case the cost of initializing an engine is higher relative to cloning one, and when initialization can be shared across engines.

Dan

I doubt cloning will make that much difference (and most likely is slower than just creating a new one). Creating engines isn’t terribly expensive anyway. I’ve been thinking about cloning, both for engines and threads. More from the point of view of what interesting things you could do with them though.

Thanks.

In my system I have to set up a number of “dynamic” data structures which are gathered into an assoc of assocs (one to rule them all), including some initialization processing.

This initialization processing happens for every new query.

Is there some measuring i could do that could help determine whether a clone would or would not offer a benefit?

thanks,

Dan

You can recorda/2 to create a frozen copy. Next use recorded/2 in the new engine/thread. That will be hard to beat.

Of course the first thing is to simply time the initialization. If you want higher resolution timing you can use call_time/2. For the engine, we get e.g.

?- call_time(engine_create(X, true, E), X).
X = time{cpu:5.378100000000274e-5, inferences:2, wall:5.602836608886719e-5},
E = <engine>(3,0x556c1b7b8e80).

The timing granularity depends on the platform (OS).

1 Like

I wonder why call_time/2 is not indexed in the website documentation search box, and also is not highlighted in the discourse post?

The first would cause the second; the highlighting plugin asks the SWI server about which things that look like predicates are actually valid.

There seems something wrong in indexing library(statistics). The individual objects are present, but do ot show up in search. See e.g.

https://www.swi-prolog.org/pldoc/doc_for?object=call_time/2

Not the fault of @jamesnvc nice plugin :slight_smile:

yes, it could be because, strangely, call_time/2 is marked as undocumented in the bottom of statistics.pl :

but in fact it is documented in the same page: