mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 08:00:20 +00:00
LibC: Remove duplicate gs touch during gettid()/getpid() fast path
While profiling I noticed that gettid() was hitting gs register twice, once for the initial fetch of s_cache_tid out of TLS for the initialization check, and then again when we return the actual value. Optimize the implementation to cache the value so we avoid the double fetch during the 99% case where it's already set. With this change gettid() goes from being the 3rd most sampled function in test-js, to pretty much disappearing into ~20th place. Additionally add the same optimization to getpid().
This commit is contained in:
parent
b9ce56aee6
commit
bbc7e8429b
Notes:
sideshowbarker
2024-07-19 04:40:07 +09:00
Author: https://github.com/bgianfo Commit: https://github.com/SerenityOS/serenity/commit/bbc7e8429bd Pull-request: https://github.com/SerenityOS/serenity/pull/2863
1 changed files with 12 additions and 6 deletions
|
@ -202,9 +202,12 @@ gid_t getgid()
|
|||
|
||||
pid_t getpid()
|
||||
{
|
||||
if (!s_cached_pid)
|
||||
s_cached_pid = syscall(SC_getpid);
|
||||
return s_cached_pid;
|
||||
int cached_pid = s_cached_pid;
|
||||
if (!cached_pid) {
|
||||
cached_pid = syscall(SC_getpid);
|
||||
s_cached_pid = cached_pid;
|
||||
}
|
||||
return cached_pid;
|
||||
}
|
||||
|
||||
pid_t getppid()
|
||||
|
@ -608,9 +611,12 @@ int truncate(const char* path, off_t length)
|
|||
|
||||
int gettid()
|
||||
{
|
||||
if (!s_cached_tid)
|
||||
s_cached_tid = syscall(SC_gettid);
|
||||
return s_cached_tid;
|
||||
int cached_tid = s_cached_tid;
|
||||
if (!cached_tid) {
|
||||
cached_tid = syscall(SC_gettid);
|
||||
s_cached_tid = cached_tid;
|
||||
}
|
||||
return cached_tid;
|
||||
}
|
||||
|
||||
int donate(int tid)
|
||||
|
|
Loading…
Reference in a new issue