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

Show task performance #445

Merged
merged 26 commits into from
Oct 21, 2024
Merged

Conversation

archbirdplus
Copy link
Contributor

image

Notes:

@archbirdplus
Copy link
Contributor Author

Looks like my "meshgen" was just more lighting under the hood. Updated to reflect that.

@IntegratedQuantum
Copy link
Member

It crashes with division by zero error when I try it:

thread 6678 panic: division by zero
/home/mint/Downloads/Cubyz/src/gui/windows/debug.zig:52:97: 0x1330e34 in render (Cubyzig)
   draw.print("    " ++ name ++ " time: {} ms ({} µs/task)", .{@divFloor(perf.utime[i], 1000), @divFloor(perf.utime[i], perf.tasks[i])}, 0, y, 8, .left);
                                                                                                ^

@archbirdplus
Copy link
Contributor Author

Is my divFloor different from yours?

@IntegratedQuantum
Copy link
Member

I don't know. Maybe you didn't test it in debug mode?

@archbirdplus
Copy link
Contributor Author

Building in debug mode takes extra steps because zig ld crashes.

@archbirdplus
Copy link
Contributor Author

Does it crash in release mode?

@IntegratedQuantum
Copy link
Member

Building in debug mode takes extra steps because zig ld crashes.

Could you send me the issue link? Then we can add it to #308

@IntegratedQuantum
Copy link
Member

It also crashes in release, looking at gdb it seems to be the same issue:

Thread 1 "Cubyzig" received signal SIGFPE, Arithmetic exception.
0x000000000110878c in windows.debug.render () at /home/mint/Downloads/Cubyz/src/gui/windows/debug.zig:52
52				draw.print("    " ++ name ++ " time: {} ms ({} µs/task)", .{@divFloor(perf.utime[i], 1000), @divFloor(perf.utime[i], perf.tasks[i])}, 0, y, 8, .left);

@archbirdplus archbirdplus deleted the task-perfs branch June 5, 2024 20:45
@archbirdplus archbirdplus restored the task-perfs branch June 5, 2024 20:45
@archbirdplus archbirdplus reopened this Jun 5, 2024
@archbirdplus
Copy link
Contributor Author

Resolved both complaints.
Zig issue: ziglang/zig#17424

@IntegratedQuantum
Copy link
Member

It's really hard to read anything here. The numbers seem to get reset every frame:

video-2024-06-06_08.17.52.mp4

@archbirdplus
Copy link
Contributor Author

In my defense, it is quite legible at 10 fps.

Copy link
Member

@IntegratedQuantum IntegratedQuantum left a comment

Choose a reason for hiding this comment

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

A couple of ideas how to improve it. Also zig reported a memory leak:

memory address 0x7fa9aed53040 leaked: 
/home/mint/Downloads/Cubyz/src/utils.zig:627:31: 0x13250c2 in create__anon_13927 (Cubyzig)
  return self.allocator.create(T) catch unreachable;
                              ^
/home/mint/Downloads/Cubyz/src/utils.zig:1040:35: 0x13152e5 in init (Cubyzig)
   .performance = allocator.create(Performance),
                                  ^
/home/mint/Downloads/Cubyz/src/main.zig:356:36: 0x1313028 in main (Cubyzig)
 threadPool = utils.ThreadPool.init(globalAllocator, @max(1, (std.Thread.getCpuCount() catch 4) -| 1));
                                   ^
/home/mint/Cubyz/compiler/zig/lib/std/start.zig:501:22: 0x1312b49 in main (Cubyzig)
            root.main();
                     ^

src/gui/windows/debug.zig Outdated Show resolved Hide resolved
src/utils.zig Outdated Show resolved Hide resolved
src/utils.zig Show resolved Hide resolved
@IntegratedQuantum
Copy link
Member

This PR has been stale for 4 months now. Do you still intend to finish this?
I think this would still be a useful addition for profiling things more quickly.

@archbirdplus
Copy link
Contributor Author

Didn't realize it was this old already. Sure, I'll finish it up.

@archbirdplus
Copy link
Contributor Author

There are actually some controversial changes here.
I added a global frameCount to only update the performance on screen every 10 frames.
I'm also not very experienced with atomics, and I don't think my readAndReset is particularly sound. Maybe I should read the whole struct atomically by packing it with @Vectors? Maybe I should have an array of {count, utime} tuples instead?

Copy link
Member

@IntegratedQuantum IntegratedQuantum left a comment

Choose a reason for hiding this comment

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

I'm also not very experienced with atomics, and I don't think my readAndReset is particularly sound. Maybe I should read the whole struct atomically by packing it with @vectors? Maybe I should have an array of {count, utime} tuples instead?

Yeah, your atomics are definitely incorrect here.

Sadly bigger atomics don't seem to work very well, see ziglang/zig#14235 (although it might be worth checking if this still happens)
The solution in this case would probably just be to use a Mutex instead of atomics.

Or I guess just don't reset the values.

src/gui/windows/debug.zig Outdated Show resolved Hide resolved
src/gui/windows/debug.zig Outdated Show resolved Hide resolved
src/gui/windows/debug.zig Outdated Show resolved Hide resolved
src/main.zig Outdated Show resolved Hide resolved
src/renderer/mesh_storage.zig Outdated Show resolved Hide resolved
src/utils.zig Show resolved Hide resolved
src/utils/.vimrc Outdated Show resolved Hide resolved
src/utils/list.zig Outdated Show resolved Hide resolved
src/utils.zig Outdated Show resolved Hide resolved
src/gui/windows/debug.zig Outdated Show resolved Hide resolved
src/utils.zig Outdated Show resolved Hide resolved
Copy link
Member

@IntegratedQuantum IntegratedQuantum left a comment

Choose a reason for hiding this comment

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

When I run this I get a memory leak:

memory address 0x756fcc252040 leaked: 
/home/mint/Downloads/archbirdplus/src/utils.zig:627:31: 0x13ab6a2 in create__anon_15345 (Cubyzig)
  return self.allocator.create(T) catch unreachable;
                              ^
/home/mint/Downloads/archbirdplus/src/utils.zig:1058:33: 0x13499d6 in init (Cubyzig)
   const self = allocator.create(Performance);
                                ^
/home/mint/Downloads/archbirdplus/src/utils.zig:1083:35: 0x1332672 in init (Cubyzig)
   .performance = Performance.init(allocator),
                                  ^
/home/mint/Downloads/archbirdplus/src/main.zig:519:36: 0x132c8e2 in main (Cubyzig)
 threadPool = utils.ThreadPool.init(globalAllocator, settings.cpuThreads orelse @max(1, (std.Thread.getCpuCount() catch 4) -| 1));
                                   ^
/home/mint/Cubyz/compiler/zig/lib/std/start.zig:608:22: 0x132bfa9 in main (Cubyzig)
            root.main();
                     ^

Memory leak

src/gui/windows/debug.zig Outdated Show resolved Hide resolved
Copy link
Member

@IntegratedQuantum IntegratedQuantum left a comment

Choose a reason for hiding this comment

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

Everything looks good now, thanks for finishing this.
I think this will be quite useful for quick profiling and detecting some of the random performance regressions on zig updates.

@IntegratedQuantum IntegratedQuantum merged commit 6b1e5ee into PixelGuys:master Oct 21, 2024
1 check passed
@archbirdplus archbirdplus deleted the task-perfs branch October 23, 2024 07:12
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