Skip to content

Task 08 : Performance follow up.#38

Merged
zzcgumn merged 4 commits intomn_mainfrom
refactor/dynamic_environment_part_twelve
Oct 13, 2025
Merged

Task 08 : Performance follow up.#38
zzcgumn merged 4 commits intomn_mainfrom
refactor/dynamic_environment_part_twelve

Conversation

@zzcgumn
Copy link
Owner

@zzcgumn zzcgumn commented Oct 13, 2025

No description provided.

…eutrality

- Lazily initialize Utilities RNG to avoid per-context std::mt19937 construction when unused
- Confirms baseline timings restored; deterministic seeding preserved
@zzcgumn zzcgumn self-assigned this Oct 13, 2025
Copilot AI review requested due to automatic review settings October 13, 2025 10:36
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Performance follow-up focusing on reducing unnecessary initialization overhead in Utilities and adding a regression test for logging behavior.

  • Lazy-initialize std::mt19937 in Utilities to avoid default construction cost when RNG is unused.
  • Add a system test verifying that log snapshots are independent of subsequent mutations.
  • Update ChangeLog to document the RNG initialization change.

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
library/src/system/util/Utilities.h Switch rng_ to lazy-initialized storage and update accessors/seed to instantiate on demand.
library/tests/system/utilities_log_snapshot_test.cpp New test ensuring log_snapshot returns an independent copy.
ChangeLog Note about lazy initialization of RNG and preserved deterministic seeding.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


private:
std::mt19937 rng_{}; // default-constructed; seed via seed()
mutable std::unique_ptr<std::mt19937> rng_; // created on demand
Copy link

Copilot AI Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching from std::mt19937 to std::unique_ptrstd::mt19937 makes Utilities non-copyable (copy ctor/assignment are implicitly deleted), which is a breaking change if callers relied on copying Utilities. Consider preserving copy semantics by either implementing an explicit deep-copy copy constructor and copy assignment operator (cloning the engine when present) or using a copyable optional-like storage (e.g., std::optionalstd::mt19937) to keep lazy initialization without removing copyability; alternatively, document and enforce non-copyable semantics if that’s intentional.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings October 13, 2025 10:39
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +41 to +48
std::mt19937& rng() {
if (!rng_) rng_ = std::make_unique<std::mt19937>();
return *rng_;
}
const std::mt19937& rng() const {
if (!rng_) rng_ = std::make_unique<std::mt19937>();
return *rng_;
}
Copy link

Copilot AI Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching from a value member to std::unique_ptr makes Utilities non-copyable (copy ctor/assignment are implicitly deleted). If Utilities was previously copyable, this is a breaking change. To preserve copy semantics and still be lazy, consider std::optionalstd::mt19937 rng_; and emplace on first use, or explicitly define copy ctor/assignment to deep-copy the engine (copy mt19937 state) and default the move operations.

Copilot uses AI. Check for mistakes.
Comment on lines +41 to +48
std::mt19937& rng() {
if (!rng_) rng_ = std::make_unique<std::mt19937>();
return *rng_;
}
const std::mt19937& rng() const {
if (!rng_) rng_ = std::make_unique<std::mt19937>();
return *rng_;
}
Copy link

Copilot AI Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The lazy-init logic is duplicated in both overloads. Factor into a small helper (e.g., ensure_rng()) to avoid divergence and ease future changes.

Copilot uses AI. Check for mistakes.
Comment on lines +45 to +48
const std::mt19937& rng() const {
if (!rng_) rng_ = std::make_unique<std::mt19937>();
return *rng_;
}
Copy link

Copilot AI Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The const accessor performs lazy initialization (via mutable) and can allocate; this is a side effect in a const method. Please document this behavior on the accessor to set expectations for callers.

Copilot uses AI. Check for mistakes.
@zzcgumn zzcgumn merged commit 75e8976 into mn_main Oct 13, 2025
3 checks passed
@zzcgumn zzcgumn deleted the refactor/dynamic_environment_part_twelve branch October 13, 2025 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants