Bladeren bron

Patch for primitive profiling and weird fix to memoizedParse:

Göran Krampe 13 jaren geleden
bovenliggende
commit
b09c400c05
6 gewijzigde bestanden met toevoegingen van 66 en 19 verwijderingen
  1. 17 2
      js/Kernel.deploy.js
  2. 26 7
      js/Kernel.js
  3. 3 1
      js/Parser.deploy.js
  4. 5 3
      js/Parser.js
  5. 11 3
      st/Kernel.st
  6. 4 3
      st/Parser.st

+ 17 - 2
js/Kernel.deploy.js

@@ -513,6 +513,19 @@ return self;}
 }),
 smalltalk.Object);
 
+smalltalk.addMethod(
+'_log_block_',
+smalltalk.method({
+selector: 'log:block:',
+fn: function (aString, aBlock){
+var self=this;
+var result=nil;
+smalltalk.send(smalltalk.send(aString, "__comma", [" time: "]), "__comma", [smalltalk.send(smalltalk.send((smalltalk.Date || Date), "_millisecondsToRun_", [(function(){return result=smalltalk.send(aBlock, "_value", []);})]), "_printString", [])]);
+return result;
+return self;}
+}),
+smalltalk.Object);
+
 
 smalltalk.addMethod(
 '_initialize',
@@ -4479,7 +4492,9 @@ selector: 'scanFrom:',
 fn: function (aStream){
 var self=this;
 var nextChunk=nil;
-nextChunk=smalltalk.send((($receiver = smalltalk.send(self['@chunkParser'], "_emptyChunk", [])).klass === smalltalk.Number) ? $receiver /smalltalk.send(self['@chunkParser'], "_chunk", []) : smalltalk.send($receiver, "__slash", [smalltalk.send(self['@chunkParser'], "_chunk", [])]), "_parse_", [aStream]);
+var par=nil;
+smalltalk.send(self, "_log_block_", ["nextChunk build", (function(){return par=(($receiver = smalltalk.send(self['@chunkParser'], "_emptyChunk", [])).klass === smalltalk.Number) ? $receiver /smalltalk.send(self['@chunkParser'], "_chunk", []) : smalltalk.send($receiver, "__slash", [smalltalk.send(self['@chunkParser'], "_chunk", [])]);})]);
+smalltalk.send(self, "_log_block_", ["nextChunk", (function(){return nextChunk=smalltalk.send(par, "_parse_", [aStream]);})]);
 (($receiver = smalltalk.send(nextChunk, "_isEmptyChunk", [])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){smalltalk.send(self, "_compileMethod_", [smalltalk.send(nextChunk, "_contents", [])]);return smalltalk.send(self, "_scanFrom_", [aStream]);})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){smalltalk.send(self, "_compileMethod_", [smalltalk.send(nextChunk, "_contents", [])]);return smalltalk.send(self, "_scanFrom_", [aStream]);})]);
 return self;}
 }),
@@ -4494,7 +4509,7 @@ var self=this;
 var method=nil;
 method=smalltalk.send(smalltalk.send((smalltalk.Compiler || Compiler), "_new", []), "_load_forClass_", [aString, self['@class']]);
 smalltalk.send(method, "_category_", [self['@category']]);
-smalltalk.send(self['@class'], "_addCompiledMethod_", [method]);
+smalltalk.send(self, "_log_block_", ["addCompiledMethod", (function(){return smalltalk.send(self['@class'], "_addCompiledMethod_", [method]);})]);
 return self;}
 }),
 smalltalk.ClassCategoryReader);

+ 26 - 7
js/Kernel.js

@@ -693,6 +693,23 @@ referencedClasses: []
 }),
 smalltalk.Object);
 
+smalltalk.addMethod(
+'_log_block_',
+smalltalk.method({
+selector: 'log:block:',
+category: 'printing',
+fn: function (aString, aBlock){
+var self=this;
+var result=nil;
+smalltalk.send(smalltalk.send(aString, "__comma", [" time: "]), "__comma", [smalltalk.send(smalltalk.send((smalltalk.Date || Date), "_millisecondsToRun_", [(function(){return result=smalltalk.send(aBlock, "_value", []);})]), "_printString", [])]);
+return result;
+return self;},
+source: unescape('log%3A%20aString%20block%3A%20aBlock%0A%0A%09%7C%20result%20%7C%0A%09%22console%20log%3A%22%20%20aString%2C%20%20%27%20time%3A%20%27%2C%20%28Date%20millisecondsToRun%3A%20%5Bresult%20%3A%3D%20aBlock%20value%5D%29%20printString.%0A%09%5Eresult%0A%0A'),
+messageSends: [unescape("%2C"), "printString", "millisecondsToRun:", "value"],
+referencedClasses: [smalltalk.Date]
+}),
+smalltalk.Object);
+
 
 smalltalk.addMethod(
 '_initialize',
@@ -6013,11 +6030,13 @@ category: 'fileIn',
 fn: function (aStream){
 var self=this;
 var nextChunk=nil;
-nextChunk=smalltalk.send((($receiver = smalltalk.send(self['@chunkParser'], "_emptyChunk", [])).klass === smalltalk.Number) ? $receiver /smalltalk.send(self['@chunkParser'], "_chunk", []) : smalltalk.send($receiver, "__slash", [smalltalk.send(self['@chunkParser'], "_chunk", [])]), "_parse_", [aStream]);
+var par=nil;
+smalltalk.send(self, "_log_block_", ["nextChunk build", (function(){return par=(($receiver = smalltalk.send(self['@chunkParser'], "_emptyChunk", [])).klass === smalltalk.Number) ? $receiver /smalltalk.send(self['@chunkParser'], "_chunk", []) : smalltalk.send($receiver, "__slash", [smalltalk.send(self['@chunkParser'], "_chunk", [])]);})]);
+smalltalk.send(self, "_log_block_", ["nextChunk", (function(){return nextChunk=smalltalk.send(par, "_parse_", [aStream]);})]);
 (($receiver = smalltalk.send(nextChunk, "_isEmptyChunk", [])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){smalltalk.send(self, "_compileMethod_", [smalltalk.send(nextChunk, "_contents", [])]);return smalltalk.send(self, "_scanFrom_", [aStream]);})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){smalltalk.send(self, "_compileMethod_", [smalltalk.send(nextChunk, "_contents", [])]);return smalltalk.send(self, "_scanFrom_", [aStream]);})]);
 return self;},
-source: unescape('scanFrom%3A%20aStream%0A%09%7C%20nextChunk%20%7C%0A%09nextChunk%20%3A%3D%20%28chunkParser%20emptyChunk%20/%20chunkParser%20chunk%29%20parse%3A%20aStream.%0A%09nextChunk%20isEmptyChunk%20ifFalse%3A%20%5B%0A%09%20%20%20%20self%20compileMethod%3A%20nextChunk%20contents.%0A%09%20%20%20%20self%20scanFrom%3A%20aStream%5D.'),
-messageSends: ["parse:", unescape("/"), "emptyChunk", "chunk", "ifFalse:", "isEmptyChunk", "compileMethod:", "contents", "scanFrom:"],
+source: unescape('scanFrom%3A%20aStream%0A%09%7C%20nextChunk%20par%20%7C%0A%09self%20log%3A%20%27nextChunk%20build%27%20block%3A%20%5Bpar%20%3A%3D%20%28chunkParser%20emptyChunk%20/%20chunkParser%20chunk%29%5D.%0A%09self%20log%3A%20%27nextChunk%27%20block%3A%20%5BnextChunk%20%3A%3D%20par%20parse%3A%20aStream%5D.%0A%09nextChunk%20isEmptyChunk%20ifFalse%3A%20%5B%0A%09%20%20%20%20self%20compileMethod%3A%20nextChunk%20contents.%0A%09%20%20%20%20self%20scanFrom%3A%20aStream%5D.'),
+messageSends: ["log:block:", unescape("/"), "emptyChunk", "chunk", "parse:", "ifFalse:", "isEmptyChunk", "compileMethod:", "contents", "scanFrom:"],
 referencedClasses: []
 }),
 smalltalk.ClassCategoryReader);
@@ -6032,11 +6051,11 @@ var self=this;
 var method=nil;
 method=smalltalk.send(smalltalk.send((smalltalk.Compiler || Compiler), "_new", []), "_load_forClass_", [aString, self['@class']]);
 smalltalk.send(method, "_category_", [self['@category']]);
-smalltalk.send(self['@class'], "_addCompiledMethod_", [method]);
+smalltalk.send(self, "_log_block_", ["addCompiledMethod", (function(){return smalltalk.send(self['@class'], "_addCompiledMethod_", [method]);})]);
 return self;},
-source: unescape('compileMethod%3A%20aString%0A%09%7C%20method%20%7C%0A%09method%20%3A%3D%20Compiler%20new%20load%3A%20aString%20forClass%3A%20class.%0A%09method%20category%3A%20category.%0A%09class%20addCompiledMethod%3A%20method'),
-messageSends: ["load:forClass:", "new", "category:", "addCompiledMethod:"],
-referencedClasses: [smalltalk.nil]
+source: unescape('compileMethod%3A%20aString%0A%09%7C%20method%20%7C%0A%09method%20%3A%3D%20Compiler%20new%20load%3A%20aString%20forClass%3A%20class.%0A%09method%20category%3A%20category.%0A%09self%20log%3A%20%27addCompiledMethod%27%20block%3A%20%5Bclass%20addCompiledMethod%3A%20method%5D'),
+messageSends: ["load:forClass:", "new", "category:", "log:block:", "addCompiledMethod:"],
+referencedClasses: [smalltalk.Compiler]
 }),
 smalltalk.ClassCategoryReader);
 

+ 3 - 1
js/Parser.deploy.js

@@ -126,11 +126,13 @@ smalltalk.method({
 selector: 'memoizedParse:',
 fn: function (aStream){
 var self=this;
+var r=nil;
 var start=nil;
 var end=nil;
 var node=nil;
 start=smalltalk.send(aStream, "_position", []);
-return smalltalk.send(smalltalk.send(self, "_memo", []), "_at_ifPresent_ifAbsent_", [start, (function(value){smalltalk.send(aStream, "_position_", [smalltalk.send(smalltalk.send(smalltalk.send(self, "_memo", []), "_at_", [start]), "_second", [])]);return smalltalk.send(value, "_first", []);}), (function(){node=smalltalk.send(self, "_parse_", [aStream]);end=smalltalk.send(aStream, "_position", []);smalltalk.send(smalltalk.send(self, "_memo", []), "_at_put_", [start, smalltalk.send((smalltalk.Array || Array), "_with_with_", [node, end])]);return node;})]);
+smalltalk.send(self, "_log_block_", ["memoizedParse", (function(){return r=smalltalk.send(smalltalk.send(self, "_memo", []), "_at_ifPresent_ifAbsent_", [start, (function(value){smalltalk.send(aStream, "_position_", [smalltalk.send(smalltalk.send(smalltalk.send(self, "_memo", []), "_at_", [start]), "_second", [])]);return smalltalk.send(value, "_first", []);}), (function(){node=smalltalk.send(self, "_parse_", [aStream]);end=smalltalk.send(aStream, "_position", []);smalltalk.send(smalltalk.send(self, "_memo", []), "_at_put_", [start, smalltalk.send((smalltalk.Array || Array), "_with_with_", [node, end])]);return node;})]);})]);
+return r;
 return self;}
 }),
 smalltalk.PPParser);

+ 5 - 3
js/Parser.js

@@ -171,14 +171,16 @@ selector: 'memoizedParse:',
 category: 'operations',
 fn: function (aStream){
 var self=this;
+var r=nil;
 var start=nil;
 var end=nil;
 var node=nil;
 start=smalltalk.send(aStream, "_position", []);
-return smalltalk.send(smalltalk.send(self, "_memo", []), "_at_ifPresent_ifAbsent_", [start, (function(value){smalltalk.send(aStream, "_position_", [smalltalk.send(smalltalk.send(smalltalk.send(self, "_memo", []), "_at_", [start]), "_second", [])]);return smalltalk.send(value, "_first", []);}), (function(){node=smalltalk.send(self, "_parse_", [aStream]);end=smalltalk.send(aStream, "_position", []);smalltalk.send(smalltalk.send(self, "_memo", []), "_at_put_", [start, smalltalk.send((smalltalk.Array || Array), "_with_with_", [node, end])]);return node;})]);
+smalltalk.send(self, "_log_block_", ["memoizedParse", (function(){return r=smalltalk.send(smalltalk.send(self, "_memo", []), "_at_ifPresent_ifAbsent_", [start, (function(value){smalltalk.send(aStream, "_position_", [smalltalk.send(smalltalk.send(smalltalk.send(self, "_memo", []), "_at_", [start]), "_second", [])]);return smalltalk.send(value, "_first", []);}), (function(){node=smalltalk.send(self, "_parse_", [aStream]);end=smalltalk.send(aStream, "_position", []);smalltalk.send(smalltalk.send(self, "_memo", []), "_at_put_", [start, smalltalk.send((smalltalk.Array || Array), "_with_with_", [node, end])]);return node;})]);})]);
+return r;
 return self;},
-source: unescape('memoizedParse%3A%20aStream%0A%09%7C%20start%20end%20node%20%7C%0A%09start%20%3A%3D%20aStream%20position.%0A%09%5Eself%20memo%20at%3A%20start%20%0A%09%20%20%20%20ifPresent%3A%20%5B%3Avalue%20%7C%0A%09%09aStream%20position%3A%20%28self%20memo%20at%3A%20start%29%20second.%0A%09%09value%20first%5D%0A%09%20%20%20%20ifAbsent%3A%20%5B%0A%09%09node%20%3A%3D%20self%20parse%3A%20aStream.%0A%09%09end%20%3A%3D%20aStream%20position.%0A%09%09self%20memo%20at%3A%20start%20put%3A%20%28Array%20with%3A%20node%20with%3A%20end%29.%0A%09%09node%5D'),
-messageSends: ["position", "at:ifPresent:ifAbsent:", "memo", "position:", "second", "at:", "first", "parse:", "at:put:", "with:with:"],
+source: unescape('memoizedParse%3A%20aStream%0A%09%7C%20r%20start%20end%20node%20%7C%0A%09start%20%3A%3D%20aStream%20position.%0A%20%20%20%20%20%20%20%20self%20log%3A%20%27memoizedParse%27%20block%3A%20%5Br%20%3A%3D%20self%20memo%20at%3A%20start%20%0A%09%20%20%20%20ifPresent%3A%20%5B%3Avalue%20%7C%0A%09%09aStream%20position%3A%20%28self%20memo%20at%3A%20start%29%20second.%0A%09%09value%20first%5D%0A%09%20%20%20%20ifAbsent%3A%20%5B%0A%09%09node%20%3A%3D%20self%20parse%3A%20aStream.%0A%09%09end%20%3A%3D%20aStream%20position.%0A%09%09self%20memo%20at%3A%20start%20put%3A%20%28Array%20with%3A%20node%20with%3A%20end%29.%0A%09%09node%5D%5D.%0A%09%5Er'),
+messageSends: ["position", "log:block:", "at:ifPresent:ifAbsent:", "memo", "position:", "second", "at:", "first", "parse:", "at:put:", "with:with:"],
 referencedClasses: [smalltalk.Array]
 }),
 smalltalk.PPParser);

+ 11 - 3
st/Kernel.st

@@ -165,6 +165,13 @@ printString
 
 printNl
 	<console.log(self)>
+!
+
+log: aString block: aBlock
+
+	| result |
+	"console log:"  aString,  ' time: ', (Date millisecondsToRun: [result := aBlock value]) printString.
+	^result
 ! !
 
 !Object methodsFor: 'testing'!
@@ -2158,8 +2165,9 @@ class: aClass category: aString
 !ClassCategoryReader methodsFor: 'fileIn'!
 
 scanFrom: aStream
-	| nextChunk |
-	nextChunk := (chunkParser emptyChunk / chunkParser chunk) parse: aStream.
+	| nextChunk par |
+	self log: 'nextChunk build' block: [par := (chunkParser emptyChunk / chunkParser chunk)].
+	self log: 'nextChunk' block: [nextChunk := par parse: aStream].
 	nextChunk isEmptyChunk ifFalse: [
 	    self compileMethod: nextChunk contents.
 	    self scanFrom: aStream].
@@ -2178,7 +2186,7 @@ compileMethod: aString
 	| method |
 	method := Compiler new load: aString forClass: class.
 	method category: category.
-	class addCompiledMethod: method
+	self log: 'addCompiledMethod' block: [class addCompiledMethod: method]
 ! !
 
 Object subclass: #Stream

+ 4 - 3
st/Parser.st

@@ -53,9 +53,9 @@ optional
 !
 
 memoizedParse: aStream
-	| start end node |
+	| r start end node |
 	start := aStream position.
-	^self memo at: start 
+        self log: 'memoizedParse' block: [r := self memo at: start 
 	    ifPresent: [:value |
 		aStream position: (self memo at: start) second.
 		value first]
@@ -63,7 +63,8 @@ memoizedParse: aStream
 		node := self parse: aStream.
 		end := aStream position.
 		self memo at: start put: (Array with: node with: end).
-		node]
+		node]].
+	^r
 ! !
 
 !PPParser methodsFor: 'parsing'!