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

Can we avoid heavy reflection usage for Converters? #1276

Open
geoand opened this issue Dec 24, 2024 · 2 comments
Open

Can we avoid heavy reflection usage for Converters? #1276

geoand opened this issue Dec 24, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@geoand
Copy link
Contributor

geoand commented Dec 24, 2024

When creating a ConfigMapping, converters are looked up via Converters.Implicit.getConverter((Class<?>) clazz) which looks like:

        static <T> Converter<T> getConverter(Class<? extends T> clazz) {
            if (clazz.isEnum()) {
                return new HyphenateEnumConverter(clazz);
            }

            // implicit converters required by the specification
            Converter<T> converter = getConverterFromStaticMethod(clazz, "of", String.class);
            if (converter == null) {
                converter = getConverterFromStaticMethod(clazz, "of", CharSequence.class);
                if (converter == null) {
                    converter = getConverterFromStaticMethod(clazz, "valueOf", String.class);
                    if (converter == null) {
                        converter = getConverterFromStaticMethod(clazz, "valueOf", CharSequence.class);
                        if (converter == null) {
                            converter = getConverterFromStaticMethod(clazz, "parse", String.class);
                            if (converter == null) {
                                converter = getConverterFromStaticMethod(clazz, "parse", CharSequence.class);
                                if (converter == null) {
                                    converter = getConverterFromConstructor(clazz, String.class);
                                    if (converter == null) {
                                        converter = getConverterFromConstructor(clazz, CharSequence.class);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return converter;
        }

In a Quarkus context, we already know this information and could pass it to Smallrye Config, right?

@radcortez
Copy link
Member

Yes, it can be done.

I made some improvements recently here:
quarkusio/quarkus#44921

Of course, this can also be improved. We already provide converters for the most common types, so this code is not used often. I did find 3 invocations in the config-quickstart, because of File, URI, and InheritableLevel.

I'll have a look.

@radcortez radcortez added the enhancement New feature or request label Jan 2, 2025
@geoand
Copy link
Contributor Author

geoand commented Jan 2, 2025

Those are exactly the ones I saw as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants