That's a fantastic example program. Thanks!
The issue is with the creation and deletion of objects with different names. A single EViews program keeps track of all named objects that get created, even if they are deleted. You're creating tens of thousands of named objects (with different names) and then deleting them, but EViews has to keep track of them even though they're deleted.
(slight caveat - EViews only keeps track if you do something with the object, simply creating and immediately deleting is fine).
I'm glad you like it. Did you know about this problem before? It took me quite some time to find this out as well; I had to comment out lines and test the program lots of times before hunting this issue down to the combination of creating objects together with performing some operation on them. Indeed, the program runs fast if you do not get the Schwarz criterion.
This of course begs the question: can something be done about this in a future version of Eviews? Or is it---like quite some other inconveniences---so deeply entrenched within Eviews that it would require rewriting the software?
Execing fixes it because a second program is creating and deleting, and that program only has to keep track of 1,000 names.
The best solution (at least in this example, not sure if possible in your actual program) is to not use new names, but rather to use the same name over and over
Of course in my actual program, the equations are doing something useful, and are also all different. If at all possible, I like to keep objects around, performing operations on them only when necessary. This allows me to change the required operations or queries on my models after a (computationally intensive) estimation method (for thousands of models). This would not be possible if I would overwrite them.
Note that if you first create all the objects and only afterwards perform the operations on them, then at first these opertations are fast. So even if many objects already exist, Eviews 'keeps track of objects' only when it has first touched them. Since the program runs identical when using exec (albeit much faster), I fail to see why this problem exists at all, i.e. why would it need to keep track of objects if it would run perfectly without doing that?
As a workaround, it seems to me that some command that clears the 'objects tracking list' is all that is needed:
I didn't test this, but would periodically save and reopen a workfile help with this?
Also, would storing objects in a database circumvent the problem?