diff options
author | pommicket <pommicket@gmail.com> | 2023-07-19 15:47:53 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2023-07-19 19:03:44 -0400 |
commit | 37f6dd7f1027e82fd12c12fca6ff0bae00e4004c (patch) | |
tree | f6ff0e5745b97adb4b418075a6bd33c8a7deec35 | |
parent | 0d84543e4a88b74aed0dec6a9ceab80b8e44c131 (diff) |
cache buffer_lsp (improves performance a fair bit)
-rw-r--r-- | buffer.c | 9 | ||||
-rw-r--r-- | main.c | 16 | ||||
-rw-r--r-- | ted.c | 1 | ||||
-rw-r--r-- | ted.h | 4 | ||||
-rw-r--r-- | text.c | 6 |
5 files changed, 19 insertions, 17 deletions
@@ -217,9 +217,6 @@ Language buffer_language(TextBuffer *buffer) { if (!buffer->path) return LANG_TEXT; - // @TODO(optimization): cache this? - // (we're calling buffer_lsp on every edit and that calls this) - if (buffer->manual_language != LANG_NONE) return (Language)buffer->manual_language; const Settings *settings = buffer->ted->default_settings; // important we don't use buffer_settings here since that would cause a loop! @@ -277,6 +274,10 @@ LSP *buffer_lsp(TextBuffer *buffer) { return NULL; if (buffer->view_only) return NULL; // we don't really want to start up an LSP in /usr/include + if (buffer->ted->frame_time - buffer->last_lsp_check < 1.0) { + return ted_get_lsp_by_id(buffer->ted, buffer->lsp_opened_in); + } + LSP *true_lsp = ted_get_lsp(buffer->ted, buffer->path, buffer_language(buffer)); LSP *curr_lsp = ted_get_lsp_by_id(buffer->ted, buffer->lsp_opened_in); if (true_lsp != curr_lsp) { @@ -285,6 +286,7 @@ LSP *buffer_lsp(TextBuffer *buffer) { if (true_lsp) buffer_send_lsp_did_open(buffer, true_lsp, NULL); } + buffer->last_lsp_check = buffer->ted->frame_time; return true_lsp; } @@ -2833,6 +2835,7 @@ bool buffer_save_as(TextBuffer *buffer, const char *new_path) { buffer->frame_latest_line_modified = buffer->nlines - 1; if (lsp) buffer_send_lsp_did_close(buffer, lsp, prev_path); + buffer->last_lsp_check = -INFINITY; // we'll send a didOpen the next time buffer_lsp is called. free(prev_path); return true; @@ -1117,13 +1117,6 @@ int main(int argc, char **argv) { buffer_check_valid(&ted->line_buffer); #endif - double frame_end_noswap = time_get_seconds(); - #if PROFILE_FRAME - { - print("Frame (noswap): %.1f ms\n", (frame_end_noswap - frame_start) * 1000); - } - #endif - if (ted->dragging_tab_node) ted->cursor = ted->cursor_move; @@ -1135,6 +1128,8 @@ int main(int argc, char **argv) { SDL_ShowCursor(SDL_DISABLE); } + double frame_end_noswap = time_get_seconds(); + #if !PROFILE_FRAME { // annoyingly, SDL_GL_SwapWindow seems to be a busy loop on my laptop for some reason... // this is why the framerate-cap settings exists @@ -1155,8 +1150,13 @@ int main(int argc, char **argv) { prev_vsync = settings->vsync; SDL_GL_SetSwapInterval(settings->vsync ? 1 : 0); } - SDL_GL_SwapWindow(window); } + #else + (void)frame_end_noswap; + SDL_GL_SetSwapInterval(0); + #endif + SDL_GL_SwapWindow(window); + PROFILE_TIME(frame_end) assert(glGetError() == 0); @@ -191,6 +191,7 @@ Settings *ted_get_settings(Ted *ted, const char *path, Language language) { } LSP *ted_get_lsp_by_id(Ted *ted, LSPID id) { + if (id == 0) return NULL; for (int i = 0; ted->lsps[i]; ++i) { LSP *lsp = ted->lsps[i]; if (lsp->id == id) @@ -414,6 +414,10 @@ typedef struct { /// which LSP this document is open in LSPID lsp_opened_in; + /// determining which LSP to use for a buffer takes some work, + /// so we don't want to do it every single frame. + /// this keeps track of the last time we actually checked what the correct LSP is. + double last_lsp_check; /// where in the undo history was the last write? used by \ref buffer_unsaved_changes u32 undo_history_write_pos; @@ -9,11 +9,6 @@ no_warn_start #endif no_warn_end -//no_warn_start -//#define STB_IMAGE_WRITE_IMPLEMENTATION -//#include "/~/apps/stb/stb_image_write.h" -//no_warn_end - typedef struct { vec2 pos; vec2 tex_coord; @@ -173,7 +168,6 @@ static void font_texture_update_if_needed(FontTexture *texture) { #if PROFILE printf("- update font texture: %.1fms\n", 1e3 * (end - start)); #endif - //stbi_write_png("out.png", FONT_TEXTURE_WIDTH, FONT_TEXTURE_HEIGHT, 1, texture->pixels, FONT_TEXTURE_WIDTH); texture->needs_update = false; } } |