Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Low performance reading the large file with use_valve_fs turned on #1577

Closed
6 tasks done
dragokas opened this issue Sep 7, 2021 · 4 comments
Closed
6 tasks done

Low performance reading the large file with use_valve_fs turned on #1577

dragokas opened this issue Sep 7, 2021 · 4 comments
Labels
Valve Issue equiv: wontfix

Comments

@dragokas
Copy link
Contributor

dragokas commented Sep 7, 2021

Help us help you

  • I have checked that my issue doesn't exist yet.
  • I have tried my absolute best to reduce the problem-space and have provided the absolute smallest test-case possible.
  • I can always reproduce the issue with the provided description below.

Environment

  • Operating System version: Windows 7
  • Game/AppID (with version if applicable): 730 (CS:GO)
  • Current SourceMod version: 1.11.0.6736
  • Current SourceMod snapshot: 1.11.0.6736
  • Current Metamod: Source snapshot: 1.11.0.1145

Description

By executing the following code the script execution timeout happens:

Problematic Code (or Steps to Reproduce)

#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>

public void OnPluginStart()
{
  int bytesRead, buff[1024];
  File hFile = OpenFile("resource/csgo_english.txt", "rb", true);
  if( hFile )
  {
  	PrintToServer("File size: %i", GetFileSize(hFile));
  
  	while( !hFile.EndOfFile() )
  	{
  		bytesRead += hFile.Read(buff, sizeof(buff), 1);
  	}
  	delete hFile;
  }
  PrintToServer("Total bytes read: %i", bytesRead);
}

int GetFileSize(File hFile)
{
  int save_pos = hFile.Position;
  hFile.Seek(0, SEEK_END);
  int size = hFile.Position;
  hFile.Seek(save_pos, SEEK_SET);
  return size;
}

Logs

File size: 5421686
L 09/07/2021 - 22:36:51: [SM] Exception reported: Script execution timed out

If you turn OFF the use_valve_fs:

File hFile = OpenFile("resource/csgo_english.txt", "rb", false);

File read almost instantly:

File size: 5421686
Total bytes read: 5421686

Problem is specific to CS:GO only.

@asherkin
Copy link
Member

asherkin commented Sep 7, 2021

Do you have any reason to believe the performance issue is on the SM side? If the performance is so much better when using SM's filesystem implementation instead of the engine's, it seems pretty clear this is a Valve issue.

@dragokas
Copy link
Contributor Author

dragokas commented Sep 7, 2021

No. I'm not familiar with implementation. The documentation is not clear about that.

bool use_valve_fs
If true, the Valve file system will be used instead. This can be used to find files existing in valve search paths, rather than solely files existing directly in the gamedir.

If that means, read function is fully switched to use Valve API, it makes sense the performance issue is solely related to Valve code.

@asherkin
Copy link
Member

asherkin commented Sep 8, 2021

Yes - use_valve_fs switches the implementation of all the FS access to use the engine's filesystem API instead of native libc functions.

@asherkin asherkin closed this as completed Sep 8, 2021
@asherkin asherkin added the Valve Issue equiv: wontfix label Sep 8, 2021
@dragokas
Copy link
Contributor Author

Just to mention, @SilvDev done a walkaround:
https://forums.alliedmods.net/showthread.php?t=334905

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Valve Issue equiv: wontfix
Projects
None yet
Development

No branches or pull requests

2 participants