Skip to content

Infrastructure: rationalise strings in TLuaInterpreter class#6636

Merged
SlySven merged 2 commits intoMudlet:developmentfrom
SlySven:Infrastructure_rationaliseStringsIn_TLuaInterpreter_class_1
Mar 15, 2023
Merged

Infrastructure: rationalise strings in TLuaInterpreter class#6636
SlySven merged 2 commits intoMudlet:developmentfrom
SlySven:Infrastructure_rationaliseStringsIn_TLuaInterpreter_class_1

Conversation

@SlySven
Copy link
Copy Markdown
Member

@SlySven SlySven commented Mar 11, 2023

Brief overview of PR changes/additions

In particular try and use ID in a uniform manner when referring to an integer number that uniquely identifies an instance of something like a room or an area in the map.

Motivation for adding to Mudlet

It became clear that there are a significant number of duplicate strings involving ID and it was possible to reduce the number of duplicate qsl(...) - which are our wrapper of QStringLiteral - by replacing each with a QString constant initialised at compile time. This is a good thing as it is bad to have multiple copies of the same string as one of these as each one is stored separately in the (Read-Only) data part of the executable.

Other info (issues closed, discussion etc)

This should close #2605.

This was prompted by @Kebap 's comments here: #6615 (comment)

In particular try and use ID in a uniform manner when referring to an
integer number that uniquely identifies an instance of something like
a room or an area in the map.

It became clear that there are a significant number of duplicate strings
involving ID and it was possible to reduce the number of duplicate
`qsl(`...`)` - which are our wrapper of `QStringLiteral` - by replacing
each with a QString constant initialised at compile time. This is a good
thing as it is bad to have multiple copies of the same string as one of
these as each one is stored separately in the (Read-Only) data part of the
executable.

This should close Mudlet#2605.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
@SlySven SlySven requested a review from a team as a code owner March 11, 2023 21:45
@SlySven SlySven requested review from a team March 11, 2023 21:45
@add-deployment-links
Copy link
Copy Markdown

add-deployment-links bot commented Mar 11, 2023

Hey there! Thanks for helping Mudlet improve. 🌟

Test versions

You can directly test the changes here:

No need to install anything - just unzip and run.
Let us know if it works well, and if it doesn't, please give details.

@SlySven
Copy link
Copy Markdown
Member Author

SlySven commented Mar 11, 2023

I think this will clash with the Lua API changes in #6615 which will need to be resolved in the second of the pair before it is merged.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
@Kebap Kebap added this to the 4.18.0 milestone Mar 12, 2023
Copy link
Copy Markdown
Member

@vadi2 vadi2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Centralising these often-repeated strings within the class makes sense. Let's not go crazy with this though - we don't know what the space savings actually are.

@SlySven
Copy link
Copy Markdown
Member Author

SlySven commented Mar 15, 2023

Centralising these often-repeated strings within the class makes sense. Let's not go crazy with this though - we don't know what the space savings actually are.

Sadly, my testing has proven confusing and disappointing, making a common instance of what would be duplicate identical QStringLiteral(...)s does not seem to reduce the size of the executable - despite this being counter to what Qt says. 😢

QLatin1Strings can (for strings that are always composed of 8-bit Latin1 characters) and QStringView (the replacement in Qt 6 for QStringRefs) for UTF-16 encoded string may reduce the executable size because they can be merged by the compiler, but there is some run-time cost compared to QStringLiteral - as one might expect there is a trade off between size and (run-time) speed.

What centralising the strings does do is reduce the different number of strings - hopefully no one is coding against the error message text but just using them for debugging when they get a nil result - so lowering the burden of deciphering problems.

@SlySven SlySven merged commit b8abfd5 into Mudlet:development Mar 15, 2023
@SlySven SlySven deleted the Infrastructure_rationaliseStringsIn_TLuaInterpreter_class_1 branch March 15, 2023 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Name areaID, roomID, labelID, etc. consistently

3 participants