Inform 7 and limitations

Fair, so far that seems to be the main case, just doing something in an inefficient manner. Something I expect is going to take me a bit to get the hang of, but hey you learn by making mistakes.

Looks like I’ve graduated to falsely attributing it directly to you in my memory :slight_smile: Last time we had this exchange, you said someone else had data. At least I was able to find that topic:

-Wade

That’s no longer true (if it ever was) because the compiled code is optimised so that (for example, and assuming there are any Before taking... rules) the Before rulebook first checks if the current action is (in this example) taking and skips over all Before taking... rules if not. Likewise for the Instead and After rulebooks.

So these rulebooks make a preliminary check for each action for which there are one or more compiled rules until they find one that matches, but not for each rule. So if, for example, you only have Before rules for 5 actions, that’s just (up to) 5 if the current action is taking...-type checks every turn, even if you have a dozen or more Before taking... rules.

The Check, Carry out and Report rulebooks have a separate rulebook for each action, (i.e. rather than a monolithic Carry out rulebook, there is a Carry out taking rulebook, a Carry out dropping rulebook etc.) and at the start of action processing the 3 rulebooks corresponding to the current action are loaded up (into rulebook variables) for checking against.

1 Like

@drpeterbatesuk I mean, do you disagree with this part of Jim Aikin’s handbook?

As noted in the box on Efficiency Tips here, Inform’s mechanism for processing the player’s input by means of rulebooks called Before, Instead, and After is inefficient. This is because there’s only one of each of these rulebooks. On the other hand, each action (such as EXAMINE, TAKE, and DROP) has its own Check, Carry Out, and Report rulebooks. What this means is that each time the player enters a command, the game will consult all of the Before, Instead, and After rules that you’ve written to see if any of them applies. In a large game, that could be hundreds of rules.

(from Code Optimization - I7 Handbook)

Or is it more that I’ve used the word rule when I should have used action or something else? I often slip by one of the specific words when I’m talking about these things.

-Wade

What Jim said may indeed have been true when he wrote it, but it is certainly incorrect now.

EDIT:

Nowadays at least, a Before rulebook is not structured as (in pseudocode)

if the current action is taking and the noun is the flower...
if the current action is taking and the noun is the button...
if the current action is taking and the noun is the jewelled crown...
if the current action is dropping and the noun is the flower...
if the current action is dropping and the noun is the button...
if the current action is dropping and the noun is the jewelled crown...

but rather, as

if the current action is taking:
    if the noun is the flower...
    if the noun is the button...
    if the noun is the jewelled crown...
if the current action is dropping:
    if the noun is the flower...
    if the noun is the button...
    if the noun is the jewelled crown...

Which remains less efficient than the mechanism used for Check, Carry out, Report, but takes the sting out of it to the point that it’s no longer relevant except for interpreters running on retro hardware

2 Likes

Does this mean that kinds of action can be used in before/instead/after, but not check/carry out/report?

I have a vague memory that the rule preambles used to be checked inside of a function each, but now they’re checked inside one function for the whole rulebook. Calling functions is slow in the VM, so avoiding a function call for non-matching rules makes a big difference.

Yes. I deal with this every day.

-Wade

1 Like