"Pops create the most lag. You can't really optimize it much past what is done now"
IMO, partly correct, just let me suggest a debatably simple/complex alternative.
Nothing changes, except all Pops are given an ID number between 1 and 1,000,000 specially for Pops. When a pop is assigned to a job, it never changes jobs on it's own, even if new jobs on a higher stratum are created. Those automatically fill when new pops are created or transferred into your empire, and still abide by limitations (say slaves in a slaver empire can't work certain jobs).
In cases where Slave jobs are already filled on a planet, but there are jobs in a higher stratum available, it'll just display the unemployment icon in the Outliner, players who are actually playing the game will handle it manually, and if using the colony management AI, they will do it instead.
The pops do not randomly shift to other jobs and prioritizing a job only applies to newly created pops in where they're placed first.
What would be nice, is a main menu-type menu where you can order jobs and prioritize ALL jobs in a specific order based on ethics and empire type (mainly normal, Corporate, Machine Empire, and Hive Mind.) with jobs being able to occupy the same slot in a "Equally distribute among these jobs" manner. The weight system could be done for this without any randomness added in like what the weight system usually has to begin with.
I have noticed that pops are randomly shifting at all times, which causes tons of problems, especially when you prioritize low-stratum jobs, and it's probably messing with performance if the AI even prioritizes jobs at all.
I've also noticed that 1 Million is a good number for late and even end-game because pop amounts rarely ever get into the hundred thousands, in fact that's so far past the endgame that you probly don't even have anything to do at that point.
Another idea, is to just ripoff Master of Orion 2, or even 4, and make it so Pops are displayed physically, stacked in the literal, exact same way and you can just pick them up and then "drop" them down into jobs that are available. The max jobs value could be easily made to give hard limits to this, and you'd not change the collapsable menus and keep those.
Jobs with only 2 Jobs could just be made to take up way less space than they do now visually, and only increasing in size as they get larger, with it taking up it's own row after hitting a large number (say... 20)
You'd allow the player to pick up a specific number of pops by clicking at say... the 5th pop from the right of this row would have you pickup 5 pops in that job.
While the pop is picked up, you can freely scroll up and down since you wouldn't need to click and drag, it'd be pretty simple and pop management would be a ton easier for new players this way.
You don't even need to give pops unique portraits, just a very generalized one atleast at first, modders will naturally create better ones anyways.
The problem of "Well what if you put pops down on anywhere that isn't a job" wouldn't exist as you wouldn't be able to, and when you close the planet screen, since you'd already have the Pop ID value, and the assigned job data, the pops held in the cursor would just go back to the jobs they were already assigned.
Assigned job data wouldn't change until they were placed in a new job.
You could simply assign each job type an ID (If they already don't have one) and not do it per job, but in general, with each planet managing how many of each job they have in total, and reporting whatever is actually filled), IE: Planet Omicron has 40 of Job 003 (Mining in this example). Planet Omicron doesn't give each available job an ID, it just knows how many of a job it has, and allows pops to be placed into it up to that max amount of 40 in total.
The AI would be able to simply pull jobs from a less prioritized one into a more needed one instantly, and I could see bugs related to this cropping up, but I still think if you put economy values into the AI scripting (Aka, AI puts jobs from minerals into energy because they have a low energy value, or they have a deficit in energy, and the job used to pull from would be based on whatever they have the most of into whatever they need the most, with Alloys and Research jobs being the highest on the "Keep if absolutely possible" list).
I have no actual idea how it's actually done, but the TL;DR is this.
Pops don't auto filter into jobs on their own, once they get into a Job, they stay there forever unless the AI moves them, or you do, and the AI doesn't move them often like an average or even good Player won't in this system. New pops automatically go into whatever job is most needed. (If you have a deficit, the pops go into jobs to remove the deficit, if not, it works as normal, prioritizing high stratum jobs instead).
Pops could be "picked up" and placed into Jobs and are displayed visually by more than just a number.
Planets wouldn't manage each job individually, just how many they have in total, and how many they have currently.
IMO, if properly implemented, this would probably fix the performance issues related to pops without the need to change much for mechanics.
Honestly, this is probly how it should always be done in a game, I'm sure pops are already given an ID number, if so, it makes literally no sense that they can even move into other jobs automatically.
The problem with stratum demotion in this system could simply be fixed by having a Job yield less while that pop is demoting, and them working in a lower stratum would enable them to demote faster anyways, since that'd make sense, and stratum demotion is really more just a nerf on normal empires anyways.
Stratum demotion wouldn't be so much a restriction as it'd just be a penalty for poor empire management at that point.
i really would love this to be implemented, but being a jaded, cycnical dude, I can't help but feel it'll never happen, even if modded into the game, it probly messes with too many hard-coded things to be workshop-able.