Skip to content

Commit 45d52d4

Browse files
committed
Call the function _updateMaxLevel() only when it's needed
1 parent a413a9f commit 45d52d4

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/core/federation.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,6 @@ export class FederatedApp extends App {
14091409
* @returns Whether every reactions at this tag are executed.
14101410
*/
14111411
protected _react(): boolean {
1412-
this._updateMaxLevel();
14131412
let r: Reaction<Variable[]>;
14141413
while (this._reactionQ.size() > 0) {
14151414
r = this._reactionQ.peek();
@@ -1565,6 +1564,7 @@ export class FederatedApp extends App {
15651564
Log.debug(this, () => {
15661565
return "In update_last_known_status_on_input ports.";
15671566
});
1567+
let anyStatusChanged = false;
15681568
this.networkReceivers.forEach(
15691569
(networkReceiver: NetworkReceiver<unknown>, portID: number) => {
15701570
// This is called when a TAG is received.
@@ -1581,9 +1581,13 @@ export class FederatedApp extends App {
15811581
);
15821582
});
15831583
networkReceiver.lastKnownStatusTag = tag;
1584+
anyStatusChanged = true;
15841585
}
15851586
}
15861587
);
1588+
if (anyStatusChanged) {
1589+
this._updateMaxLevel();
1590+
}
15871591
}
15881592

15891593
/**
@@ -1631,7 +1635,7 @@ export class FederatedApp extends App {
16311635
* Enqueue network port absent reactions that will send a MSG_TYPE_PORT_ABSENT
16321636
* message to downstream federates if a given network output port is not present.
16331637
*/
1634-
protected _enqueuePortAbsentReactions(): void {
1638+
private _enqueuePortAbsentReactions(): void {
16351639
this.portAbsentReactions.forEach((reaction) => {
16361640
this._reactionQ.push(reaction);
16371641
});
@@ -1696,6 +1700,15 @@ export class FederatedApp extends App {
16961700
});
16971701
}
16981702

1703+
/**
1704+
* @override
1705+
* Enqueue network port absent reactions and update max level for the new tag.
1706+
*/
1707+
protected _startTimeStep(): void {
1708+
this._enqueuePortAbsentReactions();
1709+
this._updateMaxLevel();
1710+
}
1711+
16991712
/**
17001713
* Send a message to a potentially remote federate's port via the RTI. This message
17011714
* is untimed, and will be timestamped by the destination federate when it is received.
@@ -1929,7 +1942,7 @@ export class FederatedApp extends App {
19291942

19301943
this._loadStartupReactions();
19311944

1932-
this._enqueuePortAbsentReactions();
1945+
this._startTimeStep();
19331946

19341947
this.rtiClient.on("connected", () => {
19351948
this.rtiClient.sendNeighborStructure(
@@ -2053,6 +2066,7 @@ export class FederatedApp extends App {
20532066
// reactions at the given tag.
20542067
this.greatestTimeAdvanceGrant = ptag;
20552068
this._isLastTAGProvisional = true;
2069+
this._updateMaxLevel();
20562070
this._addDummyEvent(ptag);
20572071
this._requestImmediateInvocationOfNext();
20582072
});

src/core/reactor.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,10 +2301,9 @@ export class App extends Reactor {
23012301
}
23022302

23032303
/**
2304-
* Enqueue network port absent reactions. This function is overriden
2305-
* by federation.ts.
2304+
* This function is overriden by federation.ts.
23062305
*/
2307-
protected _enqueuePortAbsentReactions(): void {
2306+
protected _startTimeStep(): void {
23082307
return undefined;
23092308
}
23102309

@@ -2415,8 +2414,7 @@ export class App extends Reactor {
24152414
// Advance logical time.
24162415
this._advanceTime(nextEvent.tag);
24172416

2418-
// enqueue portAbsentReactions
2419-
this._enqueuePortAbsentReactions();
2417+
this._startTimeStep();
24202418
}
24212419
// Start processing events.
24222420
this._popEvents();

0 commit comments

Comments
 (0)