-
Notifications
You must be signed in to change notification settings - Fork 264
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
Try using fseek before reading a file twice. #1499
base: main
Are you sure you want to change the base?
Conversation
Author branc116 not on autobuild list. Waiting for curator authorization before starting CI build. |
Author branc116 not on autobuild list. Waiting for curator authorization before starting CI build. |
CI Vulkan-Loader build queued with queue ID 198556. |
CI Vulkan-Loader build # 2597 running. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good PR! Yes, I concur doing a double read is a bit pointless if not performance intensive.
Definitely something which looks like a good suggestion. There is a current hole in the CI coverage for Windows platforms. But that can be ignored because this code is inside UNIX only codepaths.
CI Vulkan-Loader build # 2597 passed. |
Ah yes, about that "hole in CI". The fix for the failing windows CI checks is to rebase on main. The fix for the clang-format check is to run your change through it (or just copy what the CI check expected the code to be formatted as, since that will be the same result). |
FWIW, can probably just fall back on using fstat? |
Initially I changed it this function to use fstat, but then googled and found out that fstat is posix standard and Idk what are the differences between Bsds and linux.
Did this.
Also did this. I haven't noticed 4 spaces is used for indentation...
I don't think it is. It looks like windows is also calling to this. There is an |
Author branc116 not on autobuild list. Waiting for curator authorization before starting CI build. |
1 similar comment
Author branc116 not on autobuild list. Waiting for curator authorization before starting CI build. |
CI Vulkan-Loader build queued with queue ID 199158. |
CI Vulkan-Loader build # 2598 running. |
Yep, it is I who misread the code. Yes, this code runs on all platforms, so the lack of windows CI coverage is a bit worrysome. |
CI Vulkan-Loader build # 2598 passed. |
fstat works in all bsds that I'm aware of including FreeBSD which is Very similar to OSX and why it works in Apple too without change. However, another option is to use: https://en.cppreference.com/w/cpp/filesystem/file_size |
fstat would appear to me as the most straight forward path. I can unilaterally state that anything requiring C++ is a no-go. Not out of ideological issues, but because of requiring C++ would change the required dynamic libraries. In the future, that might change, but not for this type of change. |
Author branc116 not on autobuild list. Waiting for curator authorization before starting CI build. |
1 similar comment
Author branc116 not on autobuild list. Waiting for curator authorization before starting CI build. |
With my first commit my goal was primarily to keep compatibility across os-es and to improve performance ( reduce syscalls ) First question is if windows implementation will work
Second question is if this is optimal windows implementation...
Third question is if this will work on other COMMON_UNIX_PLATFORMS
I'd not be comfortable with you pushing this until windows ci is working and until we find posixOS/function table to check everything works... |
CI Vulkan-Loader build queued with queue ID 199730. |
CI Vulkan-Loader build # 2601 running. |
CI Vulkan-Loader build # 2601 failed. |
Damn, didn't expect so many failed test cases.. I'll look at it tomorrow. Good tests :) |
Author branc116 not on autobuild list. Waiting for curator authorization before starting CI build. |
1 similar comment
Author branc116 not on autobuild list. Waiting for curator authorization before starting CI build. |
CI Vulkan-Loader build queued with queue ID 200294. |
CI Vulkan-Loader build # 2603 running. |
Author branc116 not on autobuild list. Waiting for curator authorization before starting CI build. |
5 similar comments
Author branc116 not on autobuild list. Waiting for curator authorization before starting CI build. |
Author branc116 not on autobuild list. Waiting for curator authorization before starting CI build. |
Author branc116 not on autobuild list. Waiting for curator authorization before starting CI build. |
Author branc116 not on autobuild list. Waiting for curator authorization before starting CI build. |
Author branc116 not on autobuild list. Waiting for curator authorization before starting CI build. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More style changes but the meat of the code looks good otherwise. Style is to not mix assignment and comparisons in the same line. Just makes everything more consistent.
loader/cJSON.c
Outdated
assert(json != NULL); | ||
|
||
*json = NULL; | ||
if (VK_SUCCESS != (res = loader_read_entire_file(inst, filename, &json_buf))) goto out; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (VK_SUCCESS != (res = loader_read_entire_file(inst, filename, &json_buf))) goto out; | |
res = loader_read_entire_file(inst, filename, &json_buf); | |
if (VK_SUCCESS != res) { | |
goto out; | |
} |
loader/cJSON.c
Outdated
|
||
// Can't be a valid json if the string is of length zero | ||
if (len == 0) { | ||
if (NULL == (file = fopen(filename, "rb"))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (NULL == (file = fopen(filename, "rb"))) { | |
file = fopen(filename, "rb"); | |
if (NULL == file) { |
loader/cJSON.c
Outdated
res = VK_ERROR_INITIALIZATION_FAILED; | ||
goto out; | ||
} | ||
if (NULL == (*out_buff = (char *)loader_instance_heap_calloc(inst, stats.st_size + 1, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (NULL == (*out_buff = (char *)loader_instance_heap_calloc(inst, stats.st_size + 1, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND))) { | |
*out_buff = (char *)loader_instance_heap_calloc(inst, stats.st_size + 1, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); | |
if (NULL == *out_buff) { |
Author branc116 not on autobuild list. Waiting for curator authorization before starting CI build. |
1 similar comment
Author branc116 not on autobuild list. Waiting for curator authorization before starting CI build. |
CI Vulkan-Loader build queued with queue ID 204134. |
CI Vulkan-Loader build # 2615 running. |
CI Vulkan-Loader build # 2615 failed. |
Author branc116 not on autobuild list. Waiting for curator authorization before starting CI build. |
1 similar comment
Author branc116 not on autobuild list. Waiting for curator authorization before starting CI build. |
fopen is overriden and open is not, so fopen needs to be used if you want test to pass...
Author branc116 not on autobuild list. Waiting for curator authorization before starting CI build. |
1 similar comment
Author branc116 not on autobuild list. Waiting for curator authorization before starting CI build. |
I changed it :) |
I was testing something with vulkan and noticed that some files are being read twice.
I was supprised by that. I started digging and I found this:
And then I found this:
So because of new experimental os, everybody using this loader on linux, bsd, windows, ... has to read each json file 2 times.
Idk, in this pull request I'd just like to use fseek and then if that fails, use double read.
I also did a quick benchmark: