Abacn opened a new pull request, #40910: URL: https://github.com/apache/beam/pull/40910
`GlobalWindow` implements the singleton pattern via `__new__` by caching and returning `cls._instance`. However, because Python always invokes `__init__` on the instance returned by `__new__` (whenever `__new__` returns an instance of `cls`), defining `GlobalWindow.__init__` to call `super().__init__(GlobalWindow._getTimestampFromProto())` caused every `GlobalWindow()` call to re-parse the proto timestamp constant, allocate a new `Timestamp` object, and re-initialize `BoundedWindow._end`. Move the one-time `BoundedWindow.__init__` initialization into `GlobalWindow.__new__` when `cls._instance is None` and make `GlobalWindow.__init__` a no-op. ========== ### Benchmark Results (source: https://gist.github.com/Abacn/93fa3168450bf36838e70d853a77d2e3) | Benchmark | Baseline Median (sec / elem) | Post-Fix Median (sec / elem) | Speedup | Time Reduction | | :--- | ---: | ---: | ---: | ---: | | `GlobalWindowInstantiate` | `5.711e-07` | `7.120e-08` | **8.02x** | **-87.5%** | | `GlobalWindowsAssign` | `7.567e-07` | `2.399e-07` | **3.15x** | **-68.3%** | | `WindowIntoWorker_GlobalWindows` | `4.144e-06` | `2.934e-06` | **1.41x** | **-29.2%** | | `WindowIntoWorker_FixedWindows` | `5.970e-06` | `5.954e-06` | **1.00x** | **-0.3%** | | `WriteImplBoundedPipeline` | `1.643e-05` | `1.522e-05` | **1.08x** | **-7.4%** | <!-- Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily: - [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf). - [ ] Replace these instructions with a description of your change and why you have made it. - [ ] Mention the appropriate issue in your description (for example: `addresses #123` or `fixes #456`). - [ ] Update `CHANGES.md` with noteworthy changes. See [CONTRIBUTING.md]() for more details. --> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
