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

.ksm file optimizations #1733

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open

.ksm file optimizations #1733

wants to merge 4 commits into from

Conversation

chippydip
Copy link

Simple fixes from #1732

  • Added Equals and GetHashCode to KOSArgMarkerType so this will only get added to the arguments dictionary once (just like PseudoNull).
  • Switched argument indexing from using byte offsets to use ordinals instead so the section can be larger before switching to 2 bytes per opcode argument reference.
  • Reset previousLabel after generating argument offsets and before generating the actual code.

KOSArgMarker lacked an Equals override so every occurrence of "push
ArgMarker" would add another copy of the value to the arguments section
of a KSM file.
previousLabel wasn't reset after generating args and before generating
the actual code which could have caused issues in the unlikely event
that the first instruction's label was the natural successor to the last
instruction's label
Switched to using the argument ordinal rather than byte offset to index
arguments for each opcode. This allows upto 256 arguments before
switching to 2-byte indexes for every opcode, regardless of how long
those arguments actually are.

If an average encoded argument is 10 bytes long, this will allow 10x as
many arguments before hitting the 2-byte threshold, which can translate
to several hundred bytes saves in medium sized KSM files.
This is no longer needed
@Dunbaratu
Copy link
Member

I've been reading through some old PR's to see if any can be merged in, or if they are hopelessly too old.
Your PR looks like it's still merge-able, @chippydip.

I missed it before because it came at a time when we had a lot of things to get out and it would have increased testing burden to suddenly break all compiled KSM's right then. After putting it off, I never got back to it (sorry).

I've looked over the changes and all of them look good, but they would also require some changes to this file too:

https://github.com/KSP-KOS/KOS/blob/develop/src/kOS.Safe/Compilation/CompiledObject-doc.md

(It describes the .ksm format in detail, and your PR would change how arguments are stored, which would make some of what that document says become wrong (i.e. the arg being 20 meaning it's the 20th argument in the pack, rather than the argument at byte position 20).)

I like these changes, and if you're still around (I know this is old), would you consider adding edits to that file as part of this PR so they can be accepted as an atomic unit along with the code changes?

@chippydip
Copy link
Author

Sure thing! I'll see if I can carve out some time in the next couple days to make the doc changes.

@hvacengi hvacengi added the Pending Documentation Author is warning Reviewer not to merge this PR yet. User doc changes aren't in the PR yet. label Aug 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pending Documentation Author is warning Reviewer not to merge this PR yet. User doc changes aren't in the PR yet.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants