nova
nova copied to clipboard
Optimize hot path performance: cache config lookups and streamline list operations
Several performance bottlenecks exist in request handling hot paths, particularly repeated application:get_env/3 calls and inefficient list operations.
Changes
Cache configuration lookups in nova_router.erl
- Cache
dispatch_backendin function scope forexecute/2,lookup_url/3,add_routes/2,render_status_page/*, andadd_plugin/1 - Hoist
global_pluginslookup fromcompile_paths/3loop tocompile/3, passing via Options map - Remove redundant
lookup_url/4helper
Cache session manager in nova_session.erl
- Store session manager module in
persistent_termduring supervisor init - Replace
application:get_env/3withpersistent_term:get/2inget_session_module/0
%% Before: called on every session operation
get_session_module() ->
application:get_env(nova, session_manager, nova_session_ets).
%% After: cached lookup
get_session_module() ->
persistent_term:get(nova_session_manager, nova_session_ets).
Optimize list operations in nova_router.erl
- Replace
RouterRoutes ++ lists:append(ControllerRoutes)with singlelists:append([RouterRoutes | ControllerRoutes])inget_routes/2
Simplify module loading in nova_basic_handler.erl
- Replace
code:is_loaded/1+code:load_file/1pattern with direct try/catch - Erlang's code server auto-loads modules on first function call
- Add stacktrace arity matching to distinguish template errors from other undef errors
Impact
Reduces overhead in:
- Request routing (
execute/2) - Session operations (every
get/set) - Template rendering (
render_dtl/3) - Route compilation (
compile_paths/3loop)
[!WARNING]
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
esm.ubuntu.com
- Triggering command:
/usr/lib/apt/methods/https /usr/lib/apt/methods/https(dns block)If you need me to access, download, or install something from one of these locations, you can either:
- Configure Actions setup steps to set up my environment, which run before the firewall is enabled
- Add the appropriate URLs or hosts to the custom allowlist in this repository's Copilot coding agent settings (admins only)
Original prompt
Identify and suggest improvements to slow or inefficient code
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.