Talk:Team Fortress 2/Scripting/Script Functions/Constants

From Valve Developer Community
< Talk:Team Fortress 2
Revision as of 08:46, 9 October 2025 by Ficool2 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Premature optimizations

I've decided to change a warning into a tip, rephrase some of the tips and mark the article for clean up due to premature optimization being considered the root of all evil.

The warning were making it seem very critical and impactful, but unless someone is doing expensive code, the difference in performance is often negligible.

However, since there's no Squirrel/VScript article for optimizations (that I've been able to find) I've decided to keep the code there, until it may be moved.


If you wish to check out some of the performance differences yourself, you may paste the following commands in to the console with an active map.

script "local test = 0; for (local i = 0; i < 0x7FFFF; ++i) {test += Constants.FContents.CONTENTS_SOLID}"

script "::root_test <- Constants.FContents.CONTENTS_SOLID; local test = 0; for (local i = 0; i < 0x7FFFF; ++i) {test += ::root_test}"

script "local local_test = Constants.FContents.CONTENTS_SOLID; local test = 0; for (local i = 0; i < 0x7FFFF; ++i) {test += local_test}"

--AvastAntiPony9445 (talk) 12:15, 8 October 2025 (PDT)

See this article: https://developer.valvesoftware.com/wiki/User:Braindawg/performance
--Ficool2 (talk) 08:46, 9 October 2025 (PDT)