question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bad performance in Fresco with Recycler View, Possibly due to Kotlin?

See original GitHub issue

Reproduction

My app currently has a main page with ~60 images with a small text that are displayed using a recycler view and I would expect Fresco to handle fine since it should only be loading a few at a time, however I frequently get a “Pool Size Violation”. I’m not entirely sure if this is a fault on my side or on Fresco’s so I’m deciding to include snippets of my code

Note: It’s mostly in Kotlin, however I’m reluctant to say this is the problem since most of the interactions with Fresco are done through Java, however, I haven’t found any other faults

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerViewAdapter.ViewHolder {
        val v = LayoutInflater.from(parent.context).inflate(R.layout.list, parent, false)
        return ViewHolder(v)
    }

    //this method is binding the data on the list
    override fun onBindViewHolder(holder: RecyclerViewAdapter.ViewHolder, position: Int) {
        holder.bindItems(list[position])
    }

    //this method is giving the size of the list
    override fun getItemCount(): Int {
        return list.size
    }

    class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        fun bindItems(data: MyData) {

            val _imageView: SimpleDraweeView = itemView.findViewById(R.id.imageview)
            _imageView.setOnClickListener {
                Log.e("Click: ", data.imageURL)
            }
            //Call a Java method to set Image in Drawee
            Required_Functions.setPicture(_imageView, data.imageURL)


            //set the onclick listener for the singlt list item
            itemView.setOnClickListener({
                Log.e("ItemClicked", data.text)
            })
        }

    }
}

And here’s my referenced “setPicture” function

public static void setPicture(SimpleDraweeView img, String img_location){
        ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(img_location))
                .setResizeOptions(new ResizeOptions(100, 100))
                .build();
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setOldController(img.getController())
                .setImageRequest(request)
                .build();

        img.setController(controller);

    }

Extra Information: I’m on fresco 1.5.0 and I’ve tried this out on my Nexus 6 and an S4. On the Nexus 6, the images load but upon scrolling I get the error above and the S4 crashes upon boot-up even though the pictures are resized to 100x100.

Thanks for helping!

Solution

I’m not really sure about this but my guess is since my recycler view is entirely done in kotlin, there is an incompatibility when detecting if a item is off the screen leading to the image never being taken out of memory.

Additional Information

  • Fresco version: fresco 1.5.0
  • Platform version: Not specific to any android version or device to my knowledge

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
hanhailongcommented, Nov 21, 2017

The code is slightly problematic,in your bindItems method,should not be executed findViewBydId and setOnClickListener,should be in Kotlin’s secondary constructors

0reactions
jijichencommented, Jul 16, 2020

Hi @parthmahendra , can you share a bit more on what you find that’s missing in kotlin & recyclerview? Specifically:

it is due to my Recyclerview (and all Kotlin Recyclerviews to my knowledge) not possessing the methods to check which Recyclerview items are on screen leading to Fresco breaking down

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android RecyclerView Scrolling Performance - Stack Overflow
The problem is the poor scrolling performance. This in a RecycleView with only 8 items. In some tests I verified that in Android...
Read more >
RecyclerView Optimization - Scrolling Performance ...
In this blog, we will learn how to optimize the RecyclerView ... It leads to bad user experience as it seems that our...
Read more >
RecyclerView - Android Developers
For this reason, there are two types of position related methods in RecyclerView: layout position: Position of an item in the latest layout...
Read more >
Improve RecyclerView Performance - Medium
So let's go to solve the problem​​ Set the number of offscreen views to retain before adding them to the potentially shared recycled...
Read more >
Solving the Android Image Loading Problem: An Updated Guide
What happens if a view has multiple calls to load a URL to the same ImageView ? All three libraries here will manage...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found