Talk:Code Size

From Robowiki
Jump to navigation Jump to search

Codesize for some reason doesn't work for me. Can someone make a GUI version of it? It isn't too hard with Swing. (I've made a compression program with an algorithm of my own invention with a Swing GUI.) Or could someone post a javascript that detects it (the size) after you paste code in? Thanks! --Awesomeness 21:05, 13 March 2009 (UTC)

All you need to do to run the code size utility is "java -jar /path/to/it/codesize.jar /path/to/my/class.class". If you still can't get that working or just find it easier, you can use the "Package robot for upload" feature of Robocode which will tell you what the codesize is. Note, it's impossible for a javascript to easily detect the codesize of pastes java source code, because it's measured from the compiled bytecode not the source. --Rednaxela 21:16, 13 March 2009 (UTC)

Reducing Code Size

Well, I have a strong nano but it's roughly 280 in code size. I know I can shrink it... I'm just not very good at it. This method takes like twenty codesize points, (that's what I'll call them) and I SERIOUSLY need to shrink it. Any help please?

Code:

	public void alternate() {
		i();
		if (alternate) {
			alternate = false;
			i();
			return;
		}
			alternate = true;
	}

At least I TRIED to shrink it!


lolz,

--Awesomeness 01:22, 18 March 2009 (UTC)

The following is probably smaller codesize, but I haven't tested:

	public void alternate() {
		i();
		alternate = !alternate;
		if (!alternate) {
			i();
		}
	}

I'm not sure what i() does but I wonder if running it twice is REALLY a necessity, or if it could be worked around with very little codesize cost. Also, if codesize is critical, as it usually is for nanos, I'd suggest trying to reduce the number of number of methods in your code. If you have any methods in your code that are only called once, stop making it a seperate method. Some other tips are here in case you haven't see that. It would be easier to help if we could see more of the code, though I do have the suspicion that the biggest thing causing large codesize right now is that you may have too many methods. --Rednaxela 02:04, 18 March 2009 (UTC)

This may be even smaller

	public void alternate() {
		i();
		if (!(alternate = !alternate)) {
			i();
		}
	}

--zyx 06:36, 18 March 2009 (UTC)

  • Maybe, but I thought I tested that type of modification to not actually be helpful despite it's common usage in nanos. Doesn't hurt to test that though, I may be wrong. --Rednaxela 07:00, 18 March 2009 (UTC)
  • I have found that this type of modifications can help, but only sometimes. I think, that how many times(or some other factors) you use the same variable again affect how the compiler translates them or something like that. But my final conclusion on codesize is that everything has to be tested, because it is really hard to know before hand how it will affect codesize. --zyx 07:22, 18 March 2009 (UTC)