Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CorporationAPI - assignJob very slow #2997

Closed
ThatGuyinIT opened this issue Feb 17, 2022 · 14 comments
Closed

CorporationAPI - assignJob very slow #2997

ThatGuyinIT opened this issue Feb 17, 2022 · 14 comments

Comments

@ThatGuyinIT
Copy link

ThatGuyinIT commented Feb 17, 2022

When using ns.corporation.assignJob() in a script, it is very slow - far slower than simply clicking through the Corp UI. It feels like a defect.

let office = ns.corporation.getOffice(division.name, city);
for (const employee of office.employees) {
    let job = getNextJob(office.size, emp_num, researchDone);
    await ns.corporation.assignJob(division.name, office.loc, employee, job); // << THIS
    emp_num++;
}
@daiwai
Copy link

daiwai commented Feb 17, 2022

Looks like this is intentional:

return netscriptDelay(1000, workerScript).then(function () {

Maybe in order to prevent dynamically switching emloyees between positions for the production and selling periods during a corporation cycle?

@phyzical
Copy link
Contributor

@pigalot do you remember why? was it just a balancing thing? or maybe what @daiwai has mentioned

@ThatGuyinIT
Copy link
Author

Trying to sequentially reassign employees is proving to be painful ... 6 industries, 6 offices per industry, 100 employees per office, each taking 1 second ... this means 1 hour total time.

That or I need to figure out how to do the calls in parallel whilst waiting for 3600 promises to return before moving on.

@pigalot
Copy link
Contributor

pigalot commented Feb 18, 2022

The 1 second is intentional Its copied from the original assign.

@phyzical
Copy link
Contributor

@ThatGuyinIT a workaround is to have it running in a separate script but that is another 1tb ram (but i assume by the point your at this many employyees you should have enough money to buy more home ram)

@ThatGuyinIT
Copy link
Author

@phyzical Yes, though to make it in any way efficient, that I would want 6 scripts running in parallel (and thus 6TB), which would still only bring it down to 10 minutes to complete.

@phyzical
Copy link
Contributor

phyzical commented Feb 20, 2022

is there a reason you need to reassign so many employees? wouldn't it just be a gradual increase in all positions? (minus reassigning researchers?)

@ThatGuyinIT
Copy link
Author

@phyzical it is just ease of code - it is just easier to reassign based on percentages, e.g. first 40% are Ops, next 20% Engs etc, rather than each time count how many are in the existing role and do the delta each time, e.g. an office maxes out Research or adds 30 new hires.

It means that each time, you just run through the full list of employees again. The 1 second delay just means that a lot more logic has to be wrapped around this one single action than feels necessary.

@phyzical
Copy link
Contributor

phyzical commented Feb 21, 2022

why not just ask to assign those values? you shouldn't need to reassign.

i.e say you have 100 employees 40% would be 40, then next time say there is 200 emplyees, then 40% is 80 just provide 40 then 80 and it will just asign another 40 instead of unassigning 40 then reassigning 80

maybe we need to update the desc of it, it doesn't assign the amount each time rather gets it to the value selected.

@ThatGuyinIT
Copy link
Author

I added some logic to not reassign employees to the same jobs they already have, that saves the majority of the time.

I just don't want to spend too much time worrying about this aspect of the bitnode when the whole Corp has so many other moving pieces that have to be considered, e.g. divisions, offices, products, corp upgrades, division research, etc.

@phyzical
Copy link
Contributor

phyzical commented Feb 21, 2022

i understand, there is other prs that has been confirmed to speed things up. im just giving you some suggested workaround for now, as there is not ETA when these will make in into prod

@pigalot
Copy link
Contributor

pigalot commented Feb 21, 2022

Frankly most people don't bother with multiple working divisions so its not a problem for them, I think any change to this would go with a more robust change to the corp mechanic that would make using multiple corps more viable.

@phyzical
Copy link
Contributor

agreed, there is alot of loop all x -> y > z that is repeated that could be refactored/consolidated

@hydroflame
Copy link
Collaborator

This is intended, otherwise players can just assign their employee every corporation cycle and cheat the system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants