It's fixed at takeoff, in theory, but I don't think the perk cost updates while you're sitting in the hangar, even if the numbers change enough to change the cost.
ie, You might see 40 entering the hangar, and 20 nitlets disco while you're setting your loadout. You take off, thinking you paid 40, while the actual cost might have hit 50. You pork some stuff, die, lose 47 perks, and say, "what the fahell, ht?"