Skip to content

compare metadata for hot reloading#4

Open
todaymare wants to merge 1 commit intoGarrettGunnell:mainfrom
todaymare:main
Open

compare metadata for hot reloading#4
todaymare wants to merge 1 commit intoGarrettGunnell:mainfrom
todaymare:main

Conversation

@todaymare
Copy link
Copy Markdown

this PR makes it so the shader hot reloading code checks for a file's last modified time instead of constantly reading the file and comparing the sources


var shader_compilations = {}
var shader_code_cache = {}
var shader_compilation_time = {}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be better named shader_modified_time or raw_shader_modified_time. It's possible the shader may be modified while this is not running, making modification time != compilation time.

# Compare current shader code with cached shader code and recompile if changed
for file_path in compute_shader_file_paths:
if shader_code_cache[file_path] != FileAccess.open(file_path, FileAccess.READ).get_as_text():
if shader_compilation_time[file_path] != FileAccess.get_modified_time(file_path):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe keep the file content check after the modification time check? Would still cut down time considerably, but also avoids edge cases—for example, an autosaving editor writing the exact same content to the file.

Don't have the stats, but I'm fairly certain compilation is much more expensive in almost all cases than reading the file contents so it's best avoided if possible. Compilations should be infrequent anyway so the negligible increase in cost of also reading the file contents as well should be okay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants