Skip to content

Commit 8c740b0

Browse files
committed
Reuse LogEntry object to avoid excessive allocations when loading Timeline
1 parent 643f7e7 commit 8c740b0

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/projections/analysis/GenericLogReader.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,29 @@ public LogEntry nextProcessingEvent() throws IOException, EndOfLogSuccess
135135
{
136136
return nextEventOfType(BEGIN_PROCESSING, END_PROCESSING);
137137
}
138-
138+
139+
/**
140+
* Helper function which allocates new LogEntry object for nextEvent(LogEntry data)
141+
*/
142+
public LogEntry nextEvent() throws InputMismatchException, IOException, EndOfLogSuccess
143+
{
144+
LogEntry data = new LogEntry();
145+
return nextEvent(data);
146+
}
139147

140148
/**
141-
* Create a new LogEntryData by reading/parsing the next line from the log
149+
* Fill in a LogEntry by reading/parsing the next line from the log
142150
*
143151
* Upon reaching the end of the file, a fake END_COMPUTATION event will be produced if none was found in the log file.
144152
* After the end of the file is reached and after some END_COMPUTATION has been returned, an EndOfLogException will be thrown
145153
*
146154
* If any problem is detected when reading within a line, an IOException is produced
147155
*
156+
* Use the LogEntry object passed in rather than allocating a new one to avoid excessive object creation,
157+
* particularly useful in Timeline
148158
* */
149-
public LogEntry nextEvent() throws InputMismatchException, IOException, EndOfLogSuccess
159+
public LogEntry nextEvent(LogEntry data) throws InputMismatchException, IOException, EndOfLogSuccess
150160
{
151-
LogEntry data = new LogEntry();
152161
StsReader stsinfo = MainWindow.runObject[myRun].getSts();
153162

154163
String line = reader.readLine();

src/projections/analysis/LogLoader.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ public void createtimeline(int pe, long Begin, long End, Deque<TimelineEvent> ti
211211
return;
212212
}
213213
}
214-
//Throws EndOfLogException at end of file; break if past endTime
214+
// Throws EndOfLogException at end of file; break if past endTime
215+
// Note that the LE object is reused, filled with new data every iteration.
216+
// Ensure that stale data from a past read for another type is not used.
215217
CallStackManager cstack = new CallStackManager();
216218
ObjectId tid = null;
217219
while(true) {
@@ -420,7 +422,7 @@ public void createtimeline(int pe, long Begin, long End, Deque<TimelineEvent> ti
420422

421423
// Now, expect to read the second entry and handle
422424
// errors if necessary.
423-
LE = reader.nextEvent();
425+
LE = reader.nextEvent(LE);
424426

425427
if (LE.type != USER_EVENT_PAIR) {
426428
// DANGLING - throw away the old event
@@ -558,7 +560,7 @@ public void createtimeline(int pe, long Begin, long End, Deque<TimelineEvent> ti
558560
break;
559561
}
560562
}
561-
LE = reader.nextEvent();
563+
LE = reader.nextEvent(LE);
562564
// this will
563565
// END COMPUTATION event.
564566
if (LE.entry != -1) {

0 commit comments

Comments
 (0)