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

Method for disabling fuzzy matching in BeanWrapperFieldSetMapper [BATCH-1801] #1788

spring-projects-issues opened this issue Oct 24, 2011 · 2 comments


Copy link

@spring-projects-issues spring-projects-issues commented Oct 24, 2011

Anders Sveen opened BATCH-1801 and commented

While using BeanWrapperFieldSetMapper in a flat file reader we discovered that it was spending time iterating over all the properties in the mapped object. For every line in the file. Processing time was down to one third when we stopped using BeanWrapperFieldSetMapper.

We had set the distance to 0 (we don't need fuzzy matching), but still it did looping through the properties. It seems to me one should be able to disable this fuzzy matching either by:

  • Setting distance 0 (apparently this also enables you to mix up casing, which we discovered when we removed it)
  • Setting a "no fuzzy" attribute

The following code is the simplistic code we needed to run much faster. This requires exact match between name and property:

        FieldSetMapper<Person> beanMapper = new FieldSetMapper<Person>() {
            public Person mapFieldSet(FieldSet fieldSet) throws BindException {
                Person person = new Person();
                DataBinder binder = new DataBinder(person);
                Map<String, String> bindInstructions = new HashMap<String, String>();
                String[] names = fieldSet.getNames();
                String[] values = fieldSet.getValues();
                for (int i = 0; i < names.length; i++) {
                    bindInstructions.put(names[i], values[i].trim());

                binder.bind(new MutablePropertyValues(bindInstructions));
                if (binder.getBindingResult().hasErrors()) {
                    throw new BindException(binder.getBindingResult());

                return person;

Affects: 2.1.8

Referenced from: commits cae3f33

Backported to: 4.2.0.M3

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 19, 2012

Emmanuel Vasseur commented


I have make some tests with the new 2.1.9.RELEASE (BATCH-1813 fix), and the fixed BeanWrapperFieldSetMapper is slowest than this code.

Reading 10000 lines with 50 fields takes :

  • ~ 3 minutes with the old 2.1.8.RELEASE
  • 2,4 seconds with the new 2.1.9.RELEASE
  • 1,9 seconds with this implementation

In the BeanWrapperFieldSetMapper code, this is the call to the getBeanProperties which takes this 500ms.
This call is useless when distance is set to 0, and it can be easily removed.

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented May 30, 2019

Mahmoud Ben Hassine commented

I do confirm the issue, fuzzy matching is performed even when exact matching (distanceLimit = 0) is requested. I applied a change to bypass fuzzy matching when distanceLimit = 0 and this improves the performance by a factor of 1.5 (See JMH benchmark here).

Thank you for raising this issue!


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants