Ignore:
Timestamp:
Apr 11, 2022, 1:10:44 PM (3 years ago)
Author:
[email protected]
Message:

[JSC] Reduce use of unnecessary cryptographicallyRandom numbers
https://bugs.webkit.org/show_bug.cgi?id=239026

Reviewed by Saam Barati.

Source/JavaScriptCore:

This patch removes cryptographically random calls in some of super hot critical path.
MarkedBlock's use is very hot and it appears on Speedometer2 artrace. But this is just
a random shuffling of freelist, and WeakRandom is enough for that. This patch replaces
them with WeakRandom. It offers 0.3% improvement in Speedometer2.

  • assembler/AbstractMacroAssembler.cpp:

(JSC::AbstractMacroAssemblerBase::initializeRandom):
(WTF::printInternal):

  • assembler/AbstractMacroAssembler.h:

(JSC::AbstractMacroAssemblerBase::random):
(JSC::AbstractMacroAssembler::AbstractMacroAssembler):
(JSC::AbstractMacroAssembler::random): Deleted.

  • b3/air/AirCode.cpp:

(JSC::B3::Air::Code::Code):

  • b3/air/AirCode.h:

(JSC::B3::Air::Code::weakRandom): Deleted.

  • heap/MarkedBlockInlines.h:

(JSC::MarkedBlock::Handle::specializedSweep):

  • runtime/VM.cpp:

(JSC::VM::VM):

  • runtime/VM.h:

(JSC::VM::heapRandom):

Source/WebCore:

We use createVersion4UUIDStringWeak since there is no need to use cryptographically random numbers for KeyframeEffect names.

  • animation/KeyframeEffect.cpp:

(WebCore::KeyframeEffect::copyPropertiesFromSource):
(WebCore::KeyframeEffect::updateBlendingKeyframes):
(WebCore::KeyframeEffect::computeCSSTransitionBlendingKeyframes):

Source/WTF:

We add createVersion4UUIDStringWeak, which can generate UUID with WeakRandom numbers.

  • wtf/UUID.cpp:

(WTF::convertRandomUInt128ToUUIDVersion4):
(WTF::generateCryptographicallyRandomUUIDVersion4):
(WTF::generateWeakRandomUUIDVersion4):
(WTF::UUID::UUID):
(WTF::createVersion4UUIDStringWeak):

  • wtf/UUID.h:
  • wtf/WeakRandom.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/assembler/AbstractMacroAssembler.cpp

    r284330 r292714  
    3131#include <wtf/PrintStream.h>
    3232
     33namespace JSC {
     34
     35void AbstractMacroAssemblerBase::initializeRandom()
     36{
     37    // No strong cryptographic characteristics are necessary.
     38    static std::once_flag onceKey;
     39    static uint32_t globalCounter;
     40    std::call_once(onceKey, [&] {
     41        globalCounter = cryptographicallyRandomNumber();
     42    });
     43    ASSERT(!m_randomSource);
     44    m_randomSource.emplace(globalCounter++);
     45}
     46
     47}
     48
    3349namespace WTF {
    3450
    35 using namespace JSC;
    36 
    37 void printInternal(PrintStream& out, AbstractMacroAssemblerBase::StatusCondition condition)
     51void printInternal(PrintStream& out, JSC::AbstractMacroAssemblerBase::StatusCondition condition)
    3852{
    3953    switch (condition) {
    40     case AbstractMacroAssemblerBase::Success:
     54    case JSC::AbstractMacroAssemblerBase::Success:
    4155        out.print("Success");
    4256        return;
    43     case AbstractMacroAssemblerBase::Failure:
     57    case JSC::AbstractMacroAssemblerBase::Failure:
    4458        out.print("Failure");
    4559        return;
Note: See TracChangeset for help on using the changeset viewer.