Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some improvements to startup time. I believe this PR will reduce startup times by around 100-170ms on average.
Empty collection startup time
The improvements below apply to loading Posting such that it doesn't load any saved requests on startup.
Deferring open_api_pydantic import
Importing the open_api pydantic stuff is only required for a single CLI command, yet takes up 64ms in the importtime log.
By deferring this import to only happen when the
posting import
command runs, we can shave this time off of the startup time of the main Posting TUI. The difference here felt noticeable to me, before performing measurements.Moving HelpData class to its own module
This class was contained alongside the HelpScreen class, and is imported into many modules. However, the HelpScreen is never required on startup. HelpData (cheap import) is required on startup, HelpScreen (expensive import) is not.
Modules now import
HelpData
from a newhelp_data
module, which is far quicker to import.Pydantic -> Dataclasses for themes
I wasn't making use of the features of Pydantic when it came to themes, so by switching to dataclasses, we can get rid of some minor overhead.
On testing this later on, I was consistently finding that switching Pydantic was adding 5ms overhead over dataclasses.
Deferred loading of
watchfiles
libraryPosting watches for changes to external files using
watchfiles
. It does this watching asynchronously, and the watching logic is not required by the main Posting task, so by deferring loading, we can start up faster.Using Textual's
Lazy
widget for tab panesWithout lazy:
With lazy (request area tabs only):
With lazy (all tabs):
I was suspicious of the
Footer
widget, so done some tests with the footer removed. However, it didn't have much impact.No footer + all lazy:
The biggest win was using
Lazy
in the request area tabs. It seems to have shaved 50-100ms off of the time to first paint.Other ideas
httpx
takes 47ms to import according topython -X importtime
, which is a significant amount. This is a substantial portion of Posting's cumulative import time ~122ms. The majority of this time inhttpx
is spent importing things for thehttpx
CLI, which isn't used in Posting, and these imports are expensive.httpx._main
imports a bunch of stuff from e.g.Syntax
Rich, which imports stuff from pygments, click etc, even though it's entirely stuff relating to the httpx CLI, which I don't need. This stuff is being imported despite it never being used in Posting.Request loading improvements
Using PyYAML CLoader
PyYAML has a C implementation, which can be used if libyaml is available on the host system.
Switching to this load time when loading a collection of 18 requests from 72ms to 67ms. The time taken loading and parsing the YAML files reduced from 8ms to 3ms.