[squeak-dev] The Trunk: Collections-cmm.538.mcz
Levente Uzonyi
leves at elte.hu
Wed Oct 2 03:22:52 UTC 2013
On Tue, 1 Oct 2013, Chris Muller wrote:
> In the context of Smalltalk-80, I can understand logging straight to
> Transcript and using Transcript-specific functions (e.g., endEntry).
> Today, I consider referencing Transcript directly to be bad-form,
> simply because it tightly binds code to a particular UI.
>
> I prefer to signal Notifications to let the what-is-logged remain
> independent of the where-its-logged.
Notifications kill performance. Here's a small comparison of using no
logging at all, using Notifications for logging, and using a
ProcessLocalVariable for logging:
"No logging."
[
| counter |
counter := 0.
100000 timesRepeat: [
[
counter := counter + 1 ] value ] ] timeToRun. "10"
"Notifications."
[
| counter |
counter := 0.
[
100000 timesRepeat: [
[
counter := counter + 1.
Notification signal: counter ] value ] ]
on: Notification
do: [ :not | "logging would happen here" not resume ] ] timeToRun. "274"
"Notifications. No logger."
[
| counter |
counter := 0.
100000 timesRepeat: [
[
counter := counter + 1.
Notification signal: counter ] value ] ] timeToRun. "214"
"ProcessLocalVariable."
[
| counter |
counter := 0.
DynamicVariable
value: [ :messageToLog | "logging would happen here" ]
during: [
100000 timesRepeat: [
[
counter := counter + 1.
DynamicVariable value ifNotNil: [ :logger | logger value: counter ] ] value ] ] ] timeToRun. "34"
"ProcessLocalVariable. No logger."
[
| counter |
counter := 0.
100000 timesRepeat: [
[
counter := counter + 1.
DynamicVariable value ifNotNil: [ :logger | logger value: counter ] ] value ] ] timeToRun. "32"
The deeper the stack is (depth is 3 in this example: 2 blocks evaluations
+ 1 message send), the slower Notifications will be.
>
>> always "Transcript" or "self". Replacing #endEntry with #flush won't hurt in
>> most cases.
>
> "Most" cases, or all? I was intending to change all of MY sends of
> endEntry to flush (if any), is there a caveat?
>
Yes. Replacing #endEntry with #flush in Transcript >> #flush would
lead to infinite recursion. In some methods the receiver of #endEntry is a
Transcripter, which doesn't have its own implementation of #flush. Without
that it would break.
Levente
More information about the Squeak-dev
mailing list
|