Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

feat!: new finders API & performance improvements#12

Open
PalmDevs wants to merge 23 commits intomainfrom
feat/new-finders-api
Open

feat!: new finders API & performance improvements#12
PalmDevs wants to merge 23 commits intomainfrom
feat/new-finders-api

Conversation

@PalmDevs
Copy link
Member

@PalmDevs PalmDevs commented Jan 13, 2025

This PR introduces new finder APIs to @revenge-mod/modules and multiple performance improvements.

Here's what the new finder APIs improved:

  • Developers can pass FinderOptions to a finder in a predictable way
  • Removed the concept of raw filters as they can be confusing. You can now pass in FinderOptions.wildcard instead.
  • Removed boilerplate setup and duplicate code from Revenge Bundle's side
  • Types are better represented
  • findByFilePath is now constant time

Performance-related changes:

  • Micro-optimized pre-init code

  • Improved module hooking logic

  • Improved asset caching

  • Use truthy checks rather than in checks, as they can be up to 2.2x faster

  • Removed useless patchableModules cache

  • Fixed always-broken cache restoration

  • Yield initialized modules before non-initialized ones to defer initializing new modules

  • Eagerly find early modules like React & React Native

  • Don't find unnecessary modules that aren't needed yet

  • Only blacklist freezing module on Android

Other changes:

  • Bumped supported version in warnings plugin
  • @revenge-mod/modules no longer depends on @revenge-mod/patcher
  • @revenge-mod/react no longer depends on @revenge-mod/patcher
  • Removed a few globals
  • iOS-specific fixes for patching ErrorBoundary has been removed

As always, this PR includes major breaking changes. Developers may migrate from the old finder APIs to the new finder APIs like so:

Old finder APIs:

const {
  modules: {
    findByProps,  // (-)
    findByName,   // (-)
    
    // These helper finders stay the same, as they don't necessarily need a filter/use other filters
    findProp,
    findSingleProp,
    findByFilePath,
  }
} = revenge

const React = findByProps<typeof React>('createElement')!  // (-)
const ErrorBoundary = await findByName.async<ErrorBoundaryType>('ErrorBoundary')!  // (-)

const EventEmitter = findProp<EventEmitter>('EventEmitter')!
const TwinButtons = findSingleProp<TwinButtons>('TwinButtons')!

New finder APIs:

const {
  modules: {
    find,       // (+)
    findAsync,  // (+)
    
    filters: {  // (+)
      byProps,  // (+)
      byName,   // (+)
    },
    
    // These helper finders stay the same, as they don't necessarily need a filter/use other filters
    findProp,
    findSingleProp,
    findByFilePath,
  }
} = revenge

const React = find(byProps<typeof React>('createElement'))!  // (+)
const ErrorBoundary = await findAsync(byName<ErrorBoundary>('ErrorBoundary'))!  // (+)

const EventEmitter = findProp<EventEmitter>('EventEmitter')!
const TwinButtons = findSingleProp<TwinButtons>('TwinButtons')!

I've also removed the React and ReactNative globals to avoid polluting the environment. Use the following to access the libraries instead:

const {
  modules: {
    common: { React, ReactNative }
  }
} = revenge

⚠️ The removal of globalThis.modules and globalThis.revenge is planned.

@PalmDevs PalmDevs requested a review from nexpid January 13, 2025 18:22
@PalmDevs PalmDevs force-pushed the feat/new-finders-api branch from a3344b9 to 68c3913 Compare January 14, 2025 11:30
@PalmDevs PalmDevs requested a review from nexpid January 14, 2025 11:32
@PalmDevs PalmDevs changed the title feat(libraries/modules)!: new finders API feat!: new finders API & performance improvements Jan 14, 2025
@PalmDevs
Copy link
Member Author

This is totally broken on iOS and I do not know why, anyone willing to investigate before merge?

Copy link
Contributor

@nexpid nexpid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, i'd also like to plug #10

@PalmDevs
Copy link
Member Author

PalmDevs commented Jan 21, 2025

Apparently revenge.modules.common.toasts is undefined on this branch, so the findByFilePath probably needs to be fixed.

Fixed in bab5638. I needed to make it lazy, bruh

@PalmDevs PalmDevs force-pushed the feat/new-finders-api branch 3 times, most recently from 4ee82a6 to 56834a6 Compare January 22, 2025 19:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants