key4hep / key4hep/k4FWCore

UniqueIDGenSvc uniqueness and reproducibility considerations

Open
#294 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
14
Forks
34
Avg merge
2d 23h
Merged PRs (30d)
6

Description

Disclaimer: These are considerations in light of what the C++ standard guarantees; in practice, things might just work™

The `UniqueIDGenSvc` is described (and possibly used) as the means to get reproducible pRNG seeds. My concern lies in the reproducibility aspect due to the use of`std::hash` which per the C++ standard guarantees reproducibility only within a single execution of a program - in other words `std::hash` is free to return different values in any scenarios like:
- two different executions of the same program,
- recompilation,
- change of compiler
- different platform.

As a related issue, the`UniqueIDGenSvc` results depend also on the length of `size_t` for which only the minimal length is guaranteed by the standard, which in principle could change the values obtained on different platforms.

The result itself being `size_t` might be also problematic when `UniqueIDGenSvc` result is used as a seed for a generator with fixed width integer seed - a seed might be unique as `size_t` but non-unique after implicit casting to seed type. In practice this should be fine since the collisions shouldn't be often, it's just the users might think they have unique seed but they don't.

The last issue is caching the produced IDs in a set but the set is never cleaned which might exhaust the memory in longer running jobs. Perhaps a property could be used to disable using this cache?

Contributor guide

Open the contributing guide

Research direction

Start by locating the UniqueIDGenSvc implementation and tracing how it hashes inputs, returns size_t values, and stores generated IDs in its cache. The issue provides no file or test names; done requires an agreed implementation and tests for reproducibility, seed-width behavior, and cache lifetime.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.