WML Optimizations

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

WML Optimizations

Post by LordAwsomeness »

Hi all, so I came across a post when I was looking up LUA vs WML. I came across the term WML Optimizations and I was just wondering what are some things you can do optimize your wml to help make loading and running things a little smoother.
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
User avatar
octalot
General Code Maintainer
Posts: 786
Joined: July 17th, 2010, 7:40 pm
Location: Austria

Re: WML Optimizations

Post by octalot »

If a particular feature needs optimizing, it will often be reworked in later versions of Wesnoth; so a major trick is to have a good knowledge of the mainline campaigns, and to look at the 1.14 and 1.15 campaign WML for doing what you intend to do.

The Wiki's UsefulWMLFragments has many outdated examples, along with comments about what made them obsolete. The changelog entries for development versions (1.11.x, 1.13.x) give some hints about the new features available in 1.12.x and 1.14.x.
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: WML Optimizations

Post by Ravana »

It depends on your use case a lot. For first loading time it helps to have single-file addon instead of many files.

It is also useful to review your preprocessed WML and check if there are large duplicated fragments which should not be there.

Usually loops are faster in Lua.
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Re: WML Optimizations

Post by LordAwsomeness »

Ravana wrote: February 12th, 2020, 7:08 pm It depends on your use case a lot. For first loading time it helps to have single-file addon instead of many files.
I actually didn't know that.... I have my current add-on loading at least 25-30 cfgs... probably closer to 50...
Ravana wrote: February 12th, 2020, 7:08 pm It is also useful to review your preprocessed WML and check if there are large duplicated fragments which should not be there.
im not sure i quite follow preprocessed. Could you explain a little about that? Currently i have a lot of things loading in the prestart even and if you click too much then wesnoth will crash. is it something along those lines? Also do duplicated events slow things down? because i have a lot of turn counters going for various purposes and instead of searching through over 15k lines of wml that ive been scripting for this addon over the last 2 years, i just make a new one...
Ravana wrote: February 12th, 2020, 7:08 pm Usually loops are faster in Lua.
yea i think i want to start learning lua but i just keep getting confused everytime i look at it in files or try to read the wiki on it...
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: WML Optimizations

Post by Ravana »

First point is not important until it gets to thousands of files.

You can find wesnoth cache folder, and unpack the files until you find your addon. It is close enough to what you would get by preprocessing it yourself with wesnoth -p.
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Re: WML Optimizations

Post by LordAwsomeness »

Ravana wrote: February 13th, 2020, 7:48 am First point is not important until it gets to thousands of files.

You can find wesnoth cache folder, and unpack the files until you find your addon. It is close enough to what you would get by preprocessing it yourself with wesnoth -p.
As in literally thousands of files? Or figuratively?
What's preprocessing?
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: WML Optimizations

Post by Ravana »

Literally thousands, it provided massive benefit for ageless some years ago. Nowadays I do not bother with it, I asked for higher time limit instead.
Effect is that wesnoth only needs to read one file instead of thousands - each file access takes time.

Preprocessing is expanding macros and files into one WML document. In https://github.com/wesnoth/wesnoth/issues/4698 I have basic guide how to preprocess addon.
Post Reply