[ https://issues.apache.org/jira/browse/FLINK-37525?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Jiaan Geng updated FLINK-37525: ------------------------------- Description: Currently, the implementation of installModules has the logic show below. {code:java} for (String moduleFactoryClass : config.getSecurityModuleFactories()) { ... moduleFactory = SecurityFactoryServiceLoader.findModuleFactory(moduleFactoryClass); ... } {code} The implementation of findModuleFactory show below. {code:java} public static SecurityModuleFactory findModuleFactory(String securityModuleFactoryClass) throws NoMatchSecurityFactoryException { return findFactoryInternal( securityModuleFactoryClass, SecurityModuleFactory.class, SecurityModuleFactory.class.getClassLoader()); } {code} You can see no matter what the securityModuleFactoryClass is, the SecurityModuleFactory.class and SecurityModuleFactory.class.getClassLoader() are certain. The implementation of findFactoryInternal show below. {code:java} private static <T> T findFactoryInternal( String factoryClassCanonicalName, Class<T> factoryClass, ClassLoader classLoader) throws NoMatchSecurityFactoryException { Preconditions.checkNotNull(factoryClassCanonicalName); ServiceLoader<T> serviceLoader; if (classLoader != null) { serviceLoader = ServiceLoader.load(factoryClass, classLoader); } else { serviceLoader = ServiceLoader.load(factoryClass); } List<T> matchingFactories = new ArrayList<>(); Iterator<T> classFactoryIterator = serviceLoader.iterator(); classFactoryIterator.forEachRemaining( classFactory -> { if (factoryClassCanonicalName.matches( classFactory.getClass().getCanonicalName())) { matchingFactories.add(classFactory); } }); if (matchingFactories.size() != 1) { throw new NoMatchSecurityFactoryException( "zero or more than one security factory found", factoryClassCanonicalName, matchingFactories); } return matchingFactories.get(0); } {code} You can see findFactoryInternal load ServiceLoader and match the classFactory. These code lead to repeatedly loading ServiceLoader and match the classFactory. was: Currently, the implementation of installModules has the logic show below. {code:java} for (String moduleFactoryClass : config.getSecurityModuleFactories()) { ... moduleFactory = SecurityFactoryServiceLoader.findModuleFactory(moduleFactoryClass); ... } {code} > Introduce overload findModuleFactory to improve the performance of > installModules > --------------------------------------------------------------------------------- > > Key: FLINK-37525 > URL: https://issues.apache.org/jira/browse/FLINK-37525 > Project: Flink > Issue Type: Improvement > Components: Runtime / Configuration > Reporter: Jiaan Geng > Priority: Major > Labels: pull-request-available > > Currently, the implementation of installModules has the logic show below. > {code:java} > for (String moduleFactoryClass : config.getSecurityModuleFactories()) { > ... > moduleFactory = > SecurityFactoryServiceLoader.findModuleFactory(moduleFactoryClass); > ... > } > {code} > The implementation of findModuleFactory show below. > {code:java} > public static SecurityModuleFactory findModuleFactory(String > securityModuleFactoryClass) > throws NoMatchSecurityFactoryException { > return findFactoryInternal( > securityModuleFactoryClass, > SecurityModuleFactory.class, > SecurityModuleFactory.class.getClassLoader()); > } > {code} > You can see no matter what the securityModuleFactoryClass is, the > SecurityModuleFactory.class and SecurityModuleFactory.class.getClassLoader() > are certain. > The implementation of findFactoryInternal show below. > {code:java} > private static <T> T findFactoryInternal( > String factoryClassCanonicalName, Class<T> factoryClass, > ClassLoader classLoader) > throws NoMatchSecurityFactoryException { > Preconditions.checkNotNull(factoryClassCanonicalName); > ServiceLoader<T> serviceLoader; > if (classLoader != null) { > serviceLoader = ServiceLoader.load(factoryClass, classLoader); > } else { > serviceLoader = ServiceLoader.load(factoryClass); > } > List<T> matchingFactories = new ArrayList<>(); > Iterator<T> classFactoryIterator = serviceLoader.iterator(); > classFactoryIterator.forEachRemaining( > classFactory -> { > if (factoryClassCanonicalName.matches( > classFactory.getClass().getCanonicalName())) { > matchingFactories.add(classFactory); > } > }); > if (matchingFactories.size() != 1) { > throw new NoMatchSecurityFactoryException( > "zero or more than one security factory found", > factoryClassCanonicalName, > matchingFactories); > } > return matchingFactories.get(0); > } > {code} > You can see findFactoryInternal load ServiceLoader and match the classFactory. > These code lead to repeatedly loading ServiceLoader and match the > classFactory. -- This message was sent by Atlassian Jira (v8.20.10#820010)