Opened 13 years ago

Closed 11 years ago

#6475 closed New Feature (fixed)

Optimize compression

Reported by: Alfonso Martínez de Lizarrondo Owned by:
Priority: Normal Milestone:
Component: Project : CKPackager Version:
Keywords: Cc:

Description

I've noticed that the numbers like 1000 are output by the compressor "as is", but they can be compressed (a byte each instance) to 1e3

And a more logical improvement is that the keyboard shortcuts are generated like 1000+86 instead of putting directly 1086 that saves three bytes and saves an operation.

Other kind of optimization is that trailing semicolons before a closing bracket aren't needed:

		if ( newGetUrl )
		{
			var originalGetUrl = CKEDITOR.getUrl;
			CKEDITOR.getUrl = function ( resource )
			{
				return newGetUrl.call( CKEDITOR, resource ) ||
					originalGetUrl.call( CKEDITOR, resource );
			};
		}

should be compressed just as if it was written this way:

		if ( newGetUrl )
		{
			var originalGetUrl = CKEDITOR.getUrl;
			CKEDITOR.getUrl = function ( resource )
			{
				return newGetUrl.call( CKEDITOR, resource ) ||
					originalGetUrl.call( CKEDITOR, resource )
			}
		}

The last optimization is that self-executing functions don't need enclosing parenthesis:

<!doctype html>
<head>
<title>Removal of parenthesis</title>
</head>
<body>
<script type="text/javascript">
var a = function(){ return "OK"}();
var b = (function(){ return "OK"})();

document.write("a: " + a  + "<br>");
document.write("b: " + b  + "<br>");

</script>
</body>
</html>

Change History (4)

comment:1 Changed 13 years ago by Garry Yao

In general it's nice to see some attention to the packager is recalled.

The last optimization is that self-executing functions don't need enclosing parenthesis:

Partly correct, true only as right-hand:

var a = function(){ return "OK"}(); //OK
function(){ return "OK"}(); // Syntax error in IE and Webkit.

comment:2 Changed 13 years ago by Garry Yao

Connect to #6189, moving one comment of it's comment here.

Proposing an invariant variable (aggressive property compression) feature that caches reference like 'editor.lang.common.generalTab' denoted by definitions in .pack file.

comment:3 Changed 13 years ago by Alfonso Martínez de Lizarrondo

I don't know what kind of optimization you are suggesting there.

It shuold be possible to detect if an object has some property accesed several times (even two might be enough to be worth), so it's first cached in a local variable as we are doing manually, although this is a kind of optimization that many times it's worth doing manually because it even helps to read the code as it avoid long chains: this.editor.config --> config

Also it might be worth to create a local variable for objects like CKEDITOR or this if they are being reused.

And we could define aliases for some common properties, so we state that editor.l = editor.lang and so we could replace almost all .lang. to .l. saving 3 bytes in each instance (around 300 bytes in ckeditor.js)

comment:4 Changed 11 years ago by Piotrek Koszuliński

Resolution: fixed
Status: newclosed

We're now using Google Closure Compiler which does what is possible.

Note: See TracTickets for help on using tickets.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy