Filesystem
This page will explain different things about Gmod's Filesystem.
Searchpaths
The Filesystem uses search paths to find all necessary files.
A search path is just a normal path to a folder with a given name like GAME
You can add custom search paths by adding them to the garrysmod/cfg/mount.cfg
You can see all search paths here or you can print them with the path
command.
The LUA
search path is just a redirect to the lsv
, lsc
or LuaMenu
search path depending on your Realm.
Search order
This is how the filesystem currently searches thru the GAME
path:
- All
thirdparty
search paths (Including thegarrysmod/workshop
folder) garrysmod/overrides/
foldergarrysmod/
foldersourceengine/
folderplatform/
folder- Mounted Games
garrysmod/download/
foldergarrysmod/fallbacks
folder
This is how the filesystem currently searches thru the MOD
path:
garrysmod/overrides/
foldergarrysmod/
foldergarrysmod/fallbacks
folder
garrysmod/overrides/
The overrides folder is used by some .vpk files, and it allows you to override the results of the filesystem.
This can be useful for this like this:
You can create the folder and copy the lua
folder into it and for example edit the menu.lua
file without having to worry about Steam deleting your changes.
garrysmod/overrides
folder can cause Issues with Gmod when you for example don't copy all Lua Files.garrysmod/workshop/
The workshop folder only exists in the filesystem.
The workshop folder contains the content of all workshop addons that are mounted.
You could create it on your drive and mess with it, but you probably shouldn't.
Performance
The Performance of the filesystem can be different for everything.
Functions like file.Exists, file.Open and file.Size internally call CBaseFileSystem::Open
.
And functions like file.Time and file.IsDir use their own code.
Your goal should always be to minimize the amount of search path searched.
For example, if you try to read garrysmod.ver
, you could use the GAME
path, but the MOD
path would be far faster.
file.Exists
file.Exists for example tries to first open the file and if it can't open it, it checks if it's a directory.
Now, if you only need to check if the file exists, you should use file.Open because it skips the directory check.
Opening files
On Windows, the filesystem performance can be a bit different because of filesystem_native
.
When opening a file while filesystem_native
is set to 1
and the read mode is rb
it will first try to useĀ a CWin32ReadOnlyFile
to open it.
If it fails, it tries to use a CStdioFile
before finally returning.
The Issue with that is that it tries to open the same file two times.
The filesystem also tries to open the file for each search path, and because of that it can make a really noticeable difference if you disable filesystem_native
.
Also, the more search paths you have, the bigger the performance improvement from disabling filesystem_native
can be.
filesystem_native
?Example
An Example of the Performance difference. Base Gmod with -noaddons
and -noworkshop