Performance issue with pre-instantiated fields (project attached)

dbperftest.zip (242.3 KB)

It took me some time to figure out, why my browse view is so slow. After turning on eclipselink SQL output it was immediately apparent that there are way too many read queries created.

I finally reproduced it in a sample project by pre-instantiating fields with List type. E.g. the designer creates this:

    @JoinTable(name = "COMPANY_COST_UNIT_LINK",
            joinColumns = @JoinColumn(name = "COMPANY_ID", referencedColumnName = "ID"),
            inverseJoinColumns = @JoinColumn(name = "COST_UNIT_ID", referencedColumnName = "ID"))
    @ManyToMany
    private List<CostUnit> relatedCostUnits;

And I added the new ArrayList<>():

    @JoinTable(name = "COMPANY_COST_UNIT_LINK",
            joinColumns = @JoinColumn(name = "COMPANY_ID", referencedColumnName = "ID"),
            inverseJoinColumns = @JoinColumn(name = "COST_UNIT_ID", referencedColumnName = "ID"))
    @ManyToMany
    private List<CostUnit> relatedCostUnits = new ArrayList<>();

So you say “just keep it like the designer created it” - well, in my real project I’m using kotlin actually and with kotlin the following is created by designer and therefore you also run into the issue with the unnecessary read queries: (a lot of them)

image

The solution (for now) is to change these lines to something like:

var relations: MutableList<...>? = null

What Jmix plugin version do you use?

I’ve just tried to create a new composition attribute and the following have been generated for me:

    @Composition
    @OneToMany(mappedBy = "order")
    var items: MutableList<OrderItem> = NotInstantiatedList()

NonInstantiatedList is a special type that was introduced to prevent these eager fetches (the issue).

So, what steps did you do to make Studio generate the mutableListOf()?

1 Like

Ok, true, sorry. For the kotlin test I opened an old test project and didn’t update the plugin version there.

And for my “real” project the mutableListOf() comes from older code. I obviously didn’t add a collection field since the update of the plugin that fixed this issue.