All right. This time I followed Ameranth's murderous order and killed around one thousand NPCs. I didn't do this lightly, but it was necessary.

I operated with 'CharacterDie' (which should be identical with the common way to die in Divinity Original Sin) and with 'CharacterDestroy' commands (as Ameranth suggested) and had a look both on save file size and variable entries in the save files themselves.

First a few notes on the variable entries in save files:

As far as I see, all variable names are saved in the 'globals.lsf' file you get when you unpack the .lsv file:

Global variables have one single entry for a specific variable name (e. g. 'PrevIdleAnim'), regardless of how many characters have a variable of this name.

Local variables have one single entry for every combination of variable name and reaction/event/scriptframe name (e. g. 'CrawlingInfestation_Removed.spiderLevel' with 'spiderLevel' being the variable name).

Every variable name entry gets a 'MapValue'. By counting the appearances of this value in 'globals.lsf', where all global characters are saved, and in the levelcache files (also part of the save .lsv), where local characters are saved for each level (e. g. 'lucullaforest.lsf'), I could see how many of my unique variables were removed from the game by killing or destroying characters. Since every character had these variable names only once in their scripts they had only one entry with the MapValue of this variable (so amount of removed MapValue appearances = amount of removed characters = amount of removed variables of this name).

I only added global variables to characters. I suppose that local variables are removed along with global variables when they're getting removed. Spoiler:
CharacterDestroy completely removes characters and their variables from the game; they won't response to anything from then on. CharacterDie doesn't remove characters and variables from the game; their scripts still work (applies both to local and global characters), even if the game is saved and loaded from this save or the level is changed; there doesn't seem to be a cleanup.


Here are the results:

I: 'Base' script without new variables, saved in Luculla, at the level entrance to Cyseal

All Luculla chars alive: 6,33 MB save file size
Local LUC chars dead: 6,35 MB (+ 0.02)
All LUC chars dead: 6,50 MB (+ 0.17)

-->Instead of decreasing the save file size, it even slightly raised the size for local characters and notably increased it for global characters (which probably came from story progress, triggered by the death of important characters; I got journal entries and XP as reward).

Looking into the save files:

The amount of variable entries didn't change. All characters remained in the save file (can be found via GUID).

II: 'Base' script with 40 new global variables, saved in Luculla, at the level entrance to Cyseal

All LUC chars alive: 6,51 MB
Local LUC chars dead: 6,53 (+ 0.02)
All LUC chars dead: 6,68 MB (+ 0.17)

As we see: introducing 40 global variables into the game (which were saved for all global characters in the game and for all local characters in Luculla, since I never leaved Luculla during this testing session) increased the save file size by 0.18 MB. This difference didn't change after the death of all Chars in Luculla. It didn't approximate to the size of testing session I. The death of all global and local characters of Luculla should be enough to at least reduce the initial difference slightly (since I didn't kill the global characters of other levels, a difference, of course, would always remain; but here it didn't change anything!).

Also changing the level and coming back, saving the game didn't reduce the file size. There was no cleanup of dead characters.

Looking into the save files:

Same result as in I: The amount of variable entries didn't change. All characters remained in the save file.

The script of all characters were still ready to receive events and execute actions.

III: 'Base' script without new variables, saved in Luculla, at the level entrance to Cyseal

All Luculla chars alive: 6,33 MB save file size
Local LUC chars destroyed: 6,16 MB (- 0.17)
All LUC chars destroyed: 5,58 MB (- 0.75)
All LUC chars first dead, then destroyed: 5,75 MB (- 0.58)*

* As clearly can seen from a comparison with 'All LUC chars dead' (6,50 MB) and 'All Luculla chars alive' (6,33 MB) from test session I, the difference of 'dead + destroyed' to 'destroyed' in session II comes from the story progress, only triggered by scripted death, not by scripted destruction of the character! The story death of characters obviously adds 0.17 MB to the save file in both cases: 'dead' and 'dead + destroyed'. Without story changes both operations would have produced the same save file size.

As we see, the destruction of all local and global characters of Luculla significantly reduced the save file size.

Looking into the save files:

The amount of variable entries for global characters was reduced (I didn't study this in-depth, but I guess all entries for the destroyed global characters of Luculla were removed). All variable entries for local characters of Luculla were removed. All destroyed characters were removed from the save file (checked for a few characters, they were all gone).

IV: 'Base' script with 40 new global variables, saved in Luculla, at the level entrance to Cyseal; some previous results added to the list for comparison

All chars alive: 6,51 MB
All LUC chars dead: 6,68 MB (+ 0.17)
All LUC chars dead + destroyed: 5,87 MB (- 0.64)*
Global LUC chars destroyed: 5,89 MB (- 0.62)
Local LUC chars destroyed: 6,33 MB (- 0.18)**
All LUC chars destroyed: 5,70 MB (- 0.81)***
Local LUC and local Cyseal**** chars destroyed: 6,14 MB (- 0.37)

* this is 0.12 MB higher than without 40 additional variables; they should come from the global characters of other levels we didn't destroy

**same file size as without 40 additional variables per char!! We destroyed all local characters that contributed the additional 40 variables to the game, so we also destroyed the new variables!

*** the difference to 'dead + destroyed' (0.17) again comes from the story which the death command triggered

****similar save size reduction as local Luculla chars; there are more local chars in CYS (166 vs. 119), but Cyseal chars didn't contribute additional 40 variables per character (which increased the save file only very slightly, probably by around 0.02 MB).

--> We see: the numbers of IV also sum up quite well. The reduction sum of our 'local chars destroyed' (- 0.18) and 'global chars destroyed' (-0.62) matches almost perfectly (just a matter of rounding numbers) the 'All chars destroyed' sum (-0.81). The numbers also seem plausible when we compare them to our other tests (I-III).

Conclusion

It seems indeed possible to remove variables from the game, if we script a 'CharacterDestroy' call. Since this removes the character completely from the game, this is a very dangerous (if not 'deadly') task one should probably avoid for story relevant characters. But maybe a cleanup of local characters (which are never resurrected anyway, as far as I know) could be an option to keep the game and the save files tidy. Especially scripting heavy mods could profit from this in terms of saving/loading times. Though I'd be crazy if I recommended this to you. laugh

Possible complications haven't been investigated yet.


My mods for DOS 1 EE: FasterAnimations - QuietDay - Samaritan