sudoSolidity
sudoSolidity
TtRPC
Created by sudoSolidity on 10/6/2023 in #❓-help
Cold Boot Optimizations
I have a next.js app that uses trcp for all of the routes. I am noticing cold boots are slow. It is likely I am doing something wrong, or is there an optimization to be made? I also want to understand how next.js creates the underlying lambda functions with trcp. Is each router its lambda or something else? 
This is a mono repo I have a services package containing all of the service functions and unit tests. I then have an api package that wraps functions from the service package inside routers. The service package contains classes, for example, userService, notificationsService, and more. Each of these classes takes in a configuration. Almost everyone takes in a database connection, but some take in secrets to interact with external APIs. I have a factory that instantiates all of the classes, takes in every secret, and returns an instance of the services. Example: 
return {
 user: new UserService(databaseURL) notification: new NotificationService(SendridKey, databaseURL), moreServices… } I pass this in the context of trcp and interact with the service I want inside of each router. Example: likeThread: protectedProcedure .input( z.object({ tweetId: z.string(), }), ) .mutation(async ({ ctx, input }) => { const { serviceInternals, session } = ctx; await serviceInternals.user.toggleLike( session.user.walletAddress, input.tweetId, ); }), subscribeToEmailList: protectedProcedure .input( z.object({ email: z.string().email(), }), ) .mutation(async ({ ctx, input }) => { const { serviceInternals } = ctx; await serviceInternals.email.subscribeToMailingList(input.email); }),

 I need to be able to perform unit test on each of the service functions individually (client requires % unit code coverage), and I like having the service layer detached from the router. 

On cold boot, this takes 5-10 seconds to load. After that, it is 1 second.
7 replies