Optimize GarbageCollect and DebugWindowUpdate, bring back profiler

This commit is contained in:
krzosa
2025-12-22 17:44:21 +01:00
parent 6243cace7d
commit af1d88b07c
18 changed files with 568 additions and 117 deletions

View File

@@ -412,32 +412,20 @@ void OnCommand(Event event) {
if (event.kind == EVENT_QUIT) {
Command_Quit();
}
IF_DEBUG(AssertRanges(main.view->carets));
IF_DEBUG(AssertRanges(active.view->carets));
}
void GarbageCollect() {
if (RunGCThisFrame == false) {
return;
}
RunGCThisFrame = false;
ProfileFunction();
Allocator sys_allocator = GetSystemAllocator();
For (Views) {
IF_DEBUG(AssertRanges(it->carets));
}
For (Windows) {
if (it->sync_visibility_with_focus) {
if (it->id == ActiveWindowID) {
it->visible = true;
} else {
it->visible = false;
}
}
}
Window *window = GetWindow(ActiveWindowID);
if (ActiveWindowID.id != LastActiveLayoutWindowID.id) {
if (window->layout) {
LastActiveLayoutWindowID = ActiveWindowID;
}
}
For(Buffers) {
if (it->file_mod_time) {
int64_t new_file_mod_time = GetFileModTime(it->name);
@@ -451,8 +439,12 @@ void GarbageCollect() {
IterRemove(Views) {
IterRemovePrepare(Views);
if (it->close && it->id.id == 0) {
InvalidCodepath();
}
Buffer *buffer = GetBuffer(it->active_buffer);
if (it->kill == 0) {
if (!it->close) {
if (!buffer->garbage) {
continue;
}
@@ -472,13 +464,11 @@ void GarbageCollect() {
IterRemove(Buffers) {
IterRemovePrepare(Buffers);
if (it->id.id == 0) {
it->kill = 0;
continue;
if (it->close && it->id.id == 0) {
InvalidCodepath();
}
if (it->kill == 0) {
if (!it->close) {
if (!it->garbage) {
continue;
}
@@ -496,7 +486,11 @@ void GarbageCollect() {
IterRemove(Windows) {
IterRemovePrepare(Windows);
if (it->kill) {
if (it->close && it->id.id == 0) {
InvalidCodepath();
}
if (it->close) {
RawAppendf(GCInfoBuffer, "Wind %d %S\n", (int)it->id.id);
Dealloc(&it->goto_history);
Dealloc(&it->goto_redo);
@@ -512,10 +506,12 @@ void Update(Event event) {
Scratch scratch;
Array<Window *> order = GetWindowZOrder(scratch);
For(order) {
if (!it->visible) continue;
View *view = GetView(it->active_view);
if (!it->visible) {
continue;
}
View *view = GetView(it->active_view);
view->main_caret_on_begin_frame = view->carets[0];
view->update_scroll = true;
view->update_scroll = true;
}
OnCommand(event);
@@ -524,7 +520,27 @@ void Update(Event event) {
CommandWindowUpdate();
UpdateProcesses();
CoUpdate(&event);
GarbageCollect();
{
ProfileScope(WindowEndOfFrameVisibilityAndLastActive);
For (Windows) {
if (it->sync_visibility_with_focus) {
if (it->id == ActiveWindowID) {
it->visible = true;
} else {
it->visible = false;
}
}
}
Window *window = GetWindow(ActiveWindowID);
if (ActiveWindowID.id != LastActiveLayoutWindowID.id) {
if (window->layout) {
LastActiveLayoutWindowID = ActiveWindowID;
}
}
}
For(IterateInReverse(&order)) {
if (!it->visible) continue;
@@ -532,6 +548,8 @@ void Update(Event event) {
View *view = GetView(it->active_view);
UpdateScroll(it, !AreEqual(view->main_caret_on_begin_frame, view->carets[0]) && view->update_scroll);
}
GarbageCollect();
}
void Windows_SetupVCVarsall(mco_coro *co) {
@@ -564,9 +582,9 @@ void Windows_SetupVCVarsall(mco_coro *co) {
}
void MainLoop() {
ProfileFunction();
Scratch scratch;
FrameID += 1;
Scratch scratch;
Array<Event> frame_events = GetEventsForFrame(scratch);
Serializer ser = {EventBuffer};
For(frame_events) {