2012-01-11 10 views
8

मैं निम्नलिखित डार्ट कोड है:डार्ट द्वारा जेनरेट की गई जावास्क्रिप्ट फाइलें इतनी बड़ी क्यों हैं?

$ cat helloworld.dart 
main() => print('Hello world!'); 
$ 

जावास्क्रिप्ट डार्ट संकलक द्वारा उत्पन्न कोड के लिए ऊपर दिए गए कोड इस प्रकार है:

$ cat helloworld.dart.app.js 
function native_ListFactory__new(typeToken, length) { 
    return RTT.setTypeInfo(
     new Array(length), 
     Array.$lookupRTT(RTT.getTypeInfo(typeToken).typeArgs)); 
} 
function native_ListImplementation__indexOperator(index) { 
    return this[index]; 
} 
function native_ListImplementation__indexAssignOperator(index, value) { 
    this[index] = value; 
} 
function native_ListImplementation_get$length() { 
    return this.length; 
} 
function native_ListImplementation__setLength(length) { 
    this.length = length; 
} 
function native_ListImplementation__add(element) { 
    this.push(element); 
} 
function native_BoolImplementation_EQ(other) { 
    return typeof other == 'boolean' && this == other; 
} 
function native_BoolImplementation_toString() { 
    return this.toString(); 
} 

<snapped> 

var static$uninitialized = {}; 
var static$initializing = {}; 
function $inherits(child, parent) { 
    if (child.prototype.__proto__) { 
    child.prototype.__proto__ = parent.prototype; 
    } else { 
    function tmp() {}; 
    tmp.prototype = parent.prototype; 
    child.prototype = new tmp(); 
    child.prototype.constructor = child; 
    } 
} 
isolate$inits.push(function(){ 
    isolate$current.Duration$DartMILLISECONDS_PER_MINUTE$field = static$uninitialized; 
    isolate$current.Duration$DartMILLISECONDS_PER_HOUR$field = static$uninitialized; 
    isolate$current.Duration$DartMILLISECONDS_PER_DAY$field = static$uninitialized; 
    isolate$current.Duration$DartSECONDS_PER_HOUR$field = static$uninitialized; 
    isolate$current.Duration$DartSECONDS_PER_DAY$field = static$uninitialized; 
    isolate$current.Duration$DartMINUTES_PER_DAY$field = static$uninitialized; 
} 
); 
RunEntry(unnamedd9297f$main$member, this.arguments ? (this.arguments.slice ? [].concat(this.arguments.slice()) : this.arguments) : []); 
$ 

और helloworld.dart.app.js के आकार 102k है! helloworld.dart.js आकार 20k

$ cat helloworld.dart.js 
var e;function f(a,b){if(b>=0&&b<a.length)return b;h(i(b))};var j={},k={};function aa(a,b,c){if(b)a.g=function(){return b.call(c)}}function ba(a,b,c,d){function g(b,g,t,m){return a.call(c,d,b,g,t,m)}aa(g,b,c);return g}function l(a,b){if(a.prototype.__proto__)a.prototype.__proto__=b.prototype;else{var c=function(){};c.prototype=b.prototype;a.prototype=new c;a.prototype.constructor=a}}function ca(a,b){return typeof a=="number"&&typeof b=="number"?a+b:a.na(b)}function da(a){a/=4;return a<0?Math.ceil(a):Math.floor(a)} 
function o(a,b){if(a===void 0)return b===void 0;else if(typeof a==typeof b&&typeof a!="object")return a===b;return a.G(b)}function h(a){a&&typeof a=="object"&&Error.captureStackTrace&&Error.captureStackTrace(a);throw a;}function p(){var a=new q;a.f=s("ya",ea);a.va="";a.qa="";a.N=[];h(a)}var u={d:0}; 

<snapped> 

y.push(function(){x.fb=j;x.eb=j;x.gb=j});y.push(function(){x.Ta=j;x.Sa=j;x.Ra=j;x.Wa=j;x.Va=j;x.Ua=j});(function(a,b){if(!A){var c=new ya;oa=c;sa(c,function(){a(b)});Ea();x=c}})(function(){return qb()(1,u,"Hello world!")},this.arguments?this.arguments.slice?[].concat(this.arguments.slice()):this.arguments:[]); 
$ 

क्यों जावास्क्रिप्ट कोड है जो एक डार्ट संकलक इतना विशाल द्वारा उत्पन्न की गई है, जो -

जब अनुकूलन मोड में भाग गया, यह निम्नलिखित जावास्क्रिप्ट उत्पन्न?

ऐसी विशाल जावास्क्रिप्ट फ़ाइलों को उत्पन्न करके वे हल करने का क्या समस्या हल कर रहे हैं?

साइड नोट: जावास्क्रिप्ट फ़ाइलें इतनी बड़ी थी, इसलिए निम्न त्रुटि फेंक दिया:

Oops! Your question couldn't be submitted because: body is limited to 30000 characters; you entered 140984

+1

क्योंकि जावास्क्रिप्ट। – Aziz

+4

नए कंपाइलर्स ने उस आकार को बहुत कम कर दिया। एक 'हैलो वर्ल्ड' अब मेंढक कंपाइलर का उपयोग कर 8 लाइनें है। – moraes

उत्तर

10

यदि आप एक बेहतर जावास्क्रिप्ट भी प्राप्त करना चाहते हैं, तो डार्टसी के बजाय मेंढक कंपाइलर आज़माएं। मेंढक खुद डार्ट में लिखा है।

http://turbomanage.wordpress.com/2011/12/09/dart-dev-mode-cometh/

ध्यान दें, यह ऐसे ब्लॉग पोस्ट को ऊपर थोड़ा पुराना है। इस दौरान आप मेंढक के लिए डार्ट SDK का उपयोग कर सकते हैं: http://gsdview.appspot.com/dart-editor-archive-continuous/3058/

इस पोस्ट में भी आप के लिए ब्याज की हो सकता है, सेठ दिखाता है कि मेंढक उत्पन्न जे एस लगता है कि: http://blog.sethladd.com/2011/12/10-lessons-from-porting-javascript-to.html

यहाँ आप में मेंढक कैसे सक्षम कर सकते हैं है वर्तमान संपादक: https://groups.google.com/a/dartlang.org/group/misc/msg/5dfe04c69ed0fed3

9

Why is the javascript code which was generated from a dart code by a dart compiler is so huge?

क्योंकि यह एक डार्ट क्रम भी शामिल है।

What problem are they trying to solve by generating such huge javascript files?

ब्राउज़र में जावास्क्रिप्ट नहीं है चलाने वाले कोड की समस्या।

+3

इसमें डार्ट रनटाइम शामिल नहीं है।इससे पहले जेनरेट की गई जावास्क्रिप्ट में बहुत से अंतर्निर्मित पुस्तकालय शामिल थे, लेकिन हाल के कंपाइलर्स केवल वही शामिल करने के लिए सर्वोत्तम प्रयास करते हैं जो आवश्यक है। लॉन्च से 17k 'हैलो वर्ल्ड' अब 8 लाइनें है, उदाहरण के लिए। – moraes

12

What problem are they trying to solve by generating such huge javascript files?

डार्ट संतुलन की समस्या, अधिकांश मामलों में सर्वोत्तम होने की बजाय सिर्फ इस एक, व्यक्तिगत विशिष्ट, काल्पनिक, बेकार उदाहरण कार्यक्रम की तुलना में है कि कोई भी होगा कभी se एक उत्पादन परियोजना में उपयोग करने की कोशिश करो।

+5

यह सुनिश्चित नहीं है कि यह क्यों कम किया गया था, यह एक अच्छा जवाब है। – funkybro

-1

मुझे नहीं लगता कि यह बिंदु अक्सर डार्ट से अलग हो जाता है जितना इसे अक्सर किया जाता है: अधिकतर अनुप्रयोगों का अधिक हिस्सा संपत्ति (डेटाबेस, छवियों, ऑडियो फाइलें इत्यादि) शामिल होता है जो निश्चित हैं आकार। वास्तविक अनुप्रयोगों के लिए, तब जेएस का उत्पादन नहीं किया जाएगा, मुझे नहीं लगता कि, पूरी तरह से एक हिस्सा है क्योंकि वे "हैलो वर्ल्ड" एप्लिकेशन में हैं। अंत में, यह किसी के औजारों को चुनने के बारे में है: जेएस मूल रूप से सरल पृष्ठ व्यवहार नियंत्रण के साथ दिमाग में बनाया गया था (और बड़े या जटिल वेब अनुप्रयोग नहीं)। इस संबंध में, इसकी अभी भी इसकी जगह है (और यह एक उपकरण है जो अस्तित्व में है, उदाहरण के लिए, कंप्यूटर को "हैलो वर्ल्ड" कहने के लिए)।

संबंधित मुद्दे

 संबंधित मुद्दे