-
Notifications
You must be signed in to change notification settings - Fork 411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(internal): remove time functions from compat module #10861
base: main
Are you sure you want to change the base?
Conversation
|
@@ -16,7 +16,7 @@ class Event(object): | |||
|
|||
__slots__ = ("timestamp",) | |||
|
|||
def __init__(self, timestamp=compat.time_ns()): | |||
def __init__(self, timestamp=time.time_ns()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct? time.time_ns()
will only be evaluated once at module load time, not every time the constructor is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good shout. This shouldn't be a big issue because generally the profiler is a singleton and it is booted at start-up. The same kinda applies to tests (modulo a few delays perhaps). However, definitely something to keep in mind, just in case.
Datadog ReportBranch report: ✅ 0 Failed, 592 Passed, 694 Skipped, 20m 22.47s Total duration (16m 50.74s time saved) |
BenchmarksBenchmark execution time: 2024-09-30 11:15:11 Comparing candidate commit 7baae74 in PR branch Found 7 performance improvements and 0 performance regressions! Performance is the same for 268 metrics, 53 unstable metrics. scenario:iast_aspects-aspect_iast_do_lower
scenario:iast_aspects-aspect_iast_do_lstrip
scenario:iast_aspects-aspect_iast_do_modulo
scenario:iast_aspects-aspect_iast_do_repr
scenario:iast_aspects-aspect_iast_do_str
scenario:iast_aspects-aspect_iast_do_title
scenario:iast_aspects-aspect_iast_do_upper
|
@@ -229,11 +229,11 @@ def _open_contexts(self) -> None: | |||
contexts.append(self._collector.attach(signal)) | |||
|
|||
# Save state on the wrapping context | |||
self.set("start_time", compat.monotonic_ns()) | |||
self.set("start_time", time.monotonic_ns()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would we save much if we imported monotonic_ns
and called it directly, instead of every time looking it up from the time
module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something we should do just here, or on every place using monotonic_ns
, or on every place using any of these functions?
This PR removes 4 time-related functions from
ddtrace.internal.compat
that existed for compatibility with Python < 3.7, and replaces all uses with the corresponding functions from the builtintime
module:time_ns
,monotonic
,monotonic_ns
,process_time_ns
.The original motivation for this was noticing that the fallback code for
time_ns
had the wrong multiplier, and then checking that we don't really need these functions anymore, as we only support Python >= 3.7.Checklist
Reviewer Checklist