Closed Bug 58310 Opened 24 years ago Closed 6 months ago

Create PRTimeInSeconds() to consolidate all duplicate and costly implementations PRTimeToSeconds() and SecondsFromPR

Categories

(NSPR :: NSPR, defect, P3)

x86
All

Tracking

(Not tracked)

RESOLVED WONTFIX
Future

People

(Reporter: sspitzer, Unassigned)

References

(Blocks 1 open bug)

Details

(Keywords: perf)

Attachments

(1 file)

see http://lxr.mozilla.org/seamonkey/search?string=convertPRTimeToSeconds

there's also a variation of it in nsProfile.cpp

wtc, would this be something to add to NSPR?
No.  PRTime is 64-bit for a reason.  A 32-bit
time_t (number of seconds since 1970) will overflow
in 2036 or 2038.
the variant of the code (in nsProfile.cpp) uses the number of seconds as an
argument to srand(), which takes a uint.  I'm not concerned about overflow.

the other callers of convertPRTimeToSeconds() may be concerned.  I'll investigate. 
Changing component from Network:Cache, because it seems unrelated.
Component: Networking: Cache → Profile Manager BackEnd
-->Networking:HTTP
Assignee: neeti → darin
Component: Profile Manager BackEnd → Networking: HTTP
Target Milestone: --- → Future
I can't find any references to convertPRTimeToSeconds.  Convertions to seconds
seems to be done with the LL_* macros in nsProfile.cpp, which is pretty straight
forward.  I don't think there is any need to consolidate with other conversions.

Marking INVALID.
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → INVALID
darin: should this be in HTTP?
QA Contact: tever → httpqa
*** Bug 223804 has been marked as a duplicate of this bug. ***
Actually they are still there:
  http://lxr.mozilla.org/seamonkey/search?string=PRTimeToSeconds
and 
  http://lxr.mozilla.org/seamonkey/search?string=SecondsFromPR

But, the NSPR owners (still) refuse to have a PRUint32 PRTimeToSeconds (because
of the overflow).

So, currently the local implementors (about 20!) are now taking the risk of
overflow (in 2037 or 2100 depending on the signness of the 32bit integer).

Also, as measured in the caching code, the combination of
SecondsFromPRTime(PR_Now()) is costly (taking a fair chunk of the time spent in
caching code). 

Note, Bug 75001 (Too many calls to PR_Now in HTMLContentSink::IsTimeToNotify) is
another example of the impact of 'SecondsFromPRTime(PR_Now())'

So, a central implemented PRUint64 PR_NowSeconds(), optimized for this specific
function would reduce code as well as improve performance.  
The callers can then still convert to PRUint32 if they really want to...

May be, because it is used so often a central timer maintaining the current
'now' in seconds value? So that all callers can just retrieve this value would
be a trick to reduce the number of 'gettimeofday' calls (which are, especially
in Unix world, are costly)?
Reopening: Consolidation still has to take place ! Even if not in NSPR!
Status: RESOLVED → REOPENED
Resolution: INVALID → ---
Summary: consolidate duplicate implemenations convertPRTimeToSeconds() → consolidate duplicate implemenations PRTimeToSeconds() and SecondsFromPR
Blocks: 75001
Keywords: perf
Other aliases of uses of PR_Now with conversion to seconds are at:
http://lxr.mozilla.org/seamonkey/search?string=NOW_IN_SECONDS
http://lxr.mozilla.org/seamonkey/search?string=NowInSeconds
http://lxr.mozilla.org/seamonkey/search?string=PRTime2Seconds
http://lxr.mozilla.org/seamonkey/search?string=TimeInSecondsFromPRTime

http://lxr.mozilla.org/seamonkey/search?string=ssl_Time() 
/* returns an unsigned int containing the number of seconds in PR_Now() */

Or just as: PRInt32 elapsedSecs = (PR_Now() - startTime) / PR_USEC_PER_SEC;
Or even: nsInt64 currentTime = nsInt64(PR_Now()) / nsInt64(1000000);

So, a great number of locations where a PR_NowSeconds() is needed, but all
implement there own version.

Note, furthermore that PR_Now is generally implemented as follows:
gettimeusingOSfunction(&struct)
value = struct.seconds*1000000 + struct.milliseconds*1000; 
or variations thereof.

Even worse, for Mac, PR_Now is only accurate at seconds.



So, proposal is to extend NSPR with PR_NowSeconds, so that calculation and
conversion of microseconds is not needed, and the caller doesn't have to convert
is back to seconds again.

PRInt64 PR_NowSeconds(void)
{
    struct timeval tv;
    PRInt64 s;

    GETTIMEOFDAY(&tv);
    LL_I2L(s, tv.tv_sec);
    return s;
}


Status: REOPENED → ASSIGNED
From bug 243486: 
* The SecondsFromPRTime(PR_Now()) combination is costly: The extra conversions
on top of gettimeofday are redundant if we just want to have the current time in
seconds...
Status: ASSIGNED → RESOLVED
Closed: 21 years ago19 years ago
Resolution: --- → FIXED
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Summary: consolidate duplicate implemenations PRTimeToSeconds() and SecondsFromPR → consolidate duplicate implementations PRTimeToSeconds() and SecondsFromPR
Some timing results:
      PR_Now()/PR_USEC_PER_SEC  1000000 times:      110ms, 0.110000 us/call
                 PR_NowSeconds  1000000 times:       65ms, 0.065000 us/call

So, for windows PR_NowSeconds is twice as fast as PR_Now()/PR_USEC_PER_SEC.
For Unix case (based on ftime), the times are resp. 0.343us and 0.240us, so
there is saves even more, because all the LL calculations are skipped.
Can we change the component? This hardly seems http-specific.
Component: Networking: HTTP → NSPR
Product: Core → NSPR
Version: Trunk → other
-> defaults.

Thanks.
Assignee: darin → wtchang
Status: REOPENED → NEW
QA Contact: networking.http → wtchang
QA Contact: wtchang → nspr
Summary: consolidate duplicate implementations PRTimeToSeconds() and SecondsFromPR → Create PRTimeInSeconds() to consolidate all duplicate and costly implementations PRTimeToSeconds() and SecondsFromPR

The bug assignee didn't login in Bugzilla in the last 7 months.
:KaiE, could you have a look please?
For more information, please visit auto_nag documentation.

Assignee: wtc → nobody
Flags: needinfo?(kaie)
Flags: needinfo?(kaie)
Severity: normal → S3

In current source code baseline, PRTimeInSeconds no longer exists, so this bug is no longer relevant.

Status: NEW → RESOLVED
Closed: 19 years ago6 months ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: