Skip to content
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

Speed up bond repository update and remove some raw types #7082

Commits on Mar 8, 2024

  1. Cleanup: replace putIfAbsent-then-get with computeIfAbsent

    Use the simpler & slightly more efficient 'Map::computeIfAbsent' method
    in place of the common pattern:
    
      map.putIfAbsent(key, newValue());
      V value = map.get();
    
    (Clean up BondRepository + some cases missed from BurningManService.)
    stejbac committed Mar 8, 2024
    Configuration menu
    Copy the full SHA
    314e976 View commit details
    Browse the repository at this point in the history
  2. Generify Bond raw types & rename BondRepository type params

    Replace all raw uses of 'Bond<T extends BondedAsset>', mostly with
    wildcards (that is, 'Bond<?>'), to prevent compiler/IDE warnings.
    
    Also rename the 'T extends Bond<R>' & 'R extend BondedAsset' type params
    of 'BondRepository<..>' to 'B' & 'T' respectively, as this is a little
    less confusing.
    stejbac committed Mar 8, 2024
    Configuration menu
    Copy the full SHA
    e1a8424 View commit details
    Browse the repository at this point in the history
  3. Generify remaining raw types used by the DAO packages

    Fix raw usage of the following types, all of which (apart from
    Comparator) touch the DAO packages somewhere:
    
      Comparable, Comparator, GetStateHashesResponse, NewStateHashMessage,
      RequestStateHashesHandler, PersistenceManager
    
    (Also replace 'Integer.valueOf' with the non-boxing but otherwise
    identical method 'Integer.parseInt', in the class 'TxOutputKey'.)
    stejbac committed Mar 8, 2024
    Configuration menu
    Copy the full SHA
    c94fa98 View commit details
    Browse the repository at this point in the history

Commits on Mar 9, 2024

  1. Fix broken PreferencesTest mocks (revealed by strict Mockito stubbing)

    Fix the broken stubbing of 'PersistenceManager', which had gone stale as
    a result of the conversion of 'Preferences' to asynchronous persistence
    in commit 3f4d6e6 (2020/10/12). This caused the assertions in the
    'readPersisted' continuation blocks of 3 of the 4 tests not to be
    reached. Fix by stubbing the async 'persistenceManager::readPersisted'
    method with a callback, instead of stubbing 'getPersisted'.
    
    NOTE: Alternatively, we could add a testing-only 'readPersistedSync'
    method to 'Preferences' for consistency, as this is how the other broken
    (failing) tests resulting from 3f4d6e6 were fixed (in commit 68583d8).
    stejbac committed Mar 9, 2024
    Configuration menu
    Copy the full SHA
    7d2e050 View commit details
    Browse the repository at this point in the history
  2. Add debug perf logging to BondRepository.update()

    This is in anticipation of speedups we wish to make, as JProfiler
    reveals it to be a hotspot during new block arrivals (which are tricky
    to profile, as they occur at random).
    stejbac committed Mar 9, 2024
    Configuration menu
    Copy the full SHA
    0a1df44 View commit details
    Browse the repository at this point in the history

Commits on Apr 19, 2024

  1. Fix cubic time bug in BondedRolesRepository.update()

    Alleviate a cubic time bug during the update of the bonded roles
    repository, reducing it to quadratic running time. On Mainnet, this
    gives a roughly ten-fold speedup and should allow better scaling in the
    event that many new bonded roles are added.
    
    Replace calls to 'BondedRolesRepository.findBondedAssetByHash' with a
    lookup into a lazily initialised map of bonded assets (Roles) by hash
    (reset at the start of each call to 'BondRepository.update()' to prevent
    stale caching). This avoids rescanning the roles list for every pair of
    roles and lockup tx outputs, thus reducing the number of steps (to
    highest order) from:
    
      #roles * #roles * #lockup-tx-outputs
    
    to:
    
      #roles * #lockup-tx-outputs
    
    (The logs show 2 or 3 calls to 'BondedRepository.update()' every time a
    new block arrives, and while this was only taking around a second or so
    on Mainnet, it could potentially grow to something problematic with
    cubic scaling in the number of bonded roles.)
    stejbac committed Apr 19, 2024
    Configuration menu
    Copy the full SHA
    3a97953 View commit details
    Browse the repository at this point in the history