Set the oven to 350°F (175°C). Grease and flour a 9×13-inch baking pan.
In a medium bowl, whisk together flour, baking soda, salt, and cinnamon.
In a large bowl, beat sugar, oil, and eggs until smooth. Stir in grated carrots.
Gradually fold the dry ingredients into the wet mixture. Stir in walnuts if using.
Pour batter into the prepared pan and bake for 35–40 minutes, or until a toothpick inserted in the center comes out clean.
Let the cake cool completely before frosting.
Beat cream cheese and butter until creamy. Add powdered sugar and vanilla, mixing until smooth.
Spread frosting evenly over cooled cake and serve.