Question: Recently I started developing apps in Android studio via Kotlin, because Java seemed a bit harder. I built my first app and now, for the second, I wanna try out data binding. I follow a Udacity tutorial and there it says that I have to include `dataBinding{ enabled=True }` which I did.

The problem is that when I try to import `com.android.AppName.databinding.ActivityMainBinding`
the name is red, even though I declared the variable below, in the `onCreate`
Everything related to data binding is red pretty much. 

I can't figure out what's the problem. Any suggestion would help. Thanks!

Answer: 
Firstly I would suggest moving away from `List.Remove` since worst case it needs to check each item to find the one to remove. Instead of removing shards that are being processed from the list of unprocessed shards, you could keep another list of processed shards and add to that. Then your condition checking if the connected shard is unprocessed would become `if(!processedShards.Contains(connectedShard))`. 

You can read more about the performance of List operations on the [microsoft docs](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.remove?view=netframework-4.8), just scroll down to the Remarks section.

---

Another improvement would be to find an alternative to `List.Contains` when checking if a shard has been processed. Similarly to `List.Remove`, it needs to potentially check each item in the list before it can tell if the item is present. 

One way to do so would be to use a [HashSet](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1?view=netframework-4.8) instead of a List. It provides much quicker ways to access specific items and to check if items are present in the collection. It also provides many of the same methods so refactoring should be a breeze.

---

Just as a note, personally I wouldn't bother with optimization until performance becomes an issue. You might find these improvements gain you next to nothing as your collections just aren't large enough. If you have not yet, check out the [Unity profiler](https://docs.unity3d.com/Manual/Profiler.html) and from there gauge where your big performance hits are coming from.
It seems the script slowed down the most at the recursion of the ProcessShard() method so I renamed and rewrote the method as ProcessShards() that uses a while loop and a Queue to process all the shards. The performance was around ten times better on a chunk with 100 shards.

```
    // process shards
    private void ProcessShards()
    {
        // create a list for shards to process
        Queue<GameObject> shardsToProcess = new Queue<GameObject>();

        // select the first shard to process
        shardsToProcess.Enqueue(unprocessedShards[0]);

        // remove shard from unprocessed list
        unprocessedShards.Remove(unprocessedShards[0]);

        // loop while there are shards to process
        while (shardsToProcess.Count > 0)
        {
            // get the first shard to process
            GameObject shard = shardsToProcess.Dequeue();

            // add the shard to this chunk
            shard.GetComponent<Shard>().parentChunk = gameObject;

            // loop through all shards connected to the given shard
            foreach (GameObject connectedShard in shard.GetComponent<Shard>().connectedShards)
            {
                // connected shard has not been processed yet
                if (unprocessedShards.Contains(connectedShard))
                {
                    // add shard to be processed
                    shardsToProcess.Enqueue(connectedShard);

                    // remove shard from unprocessed list
                    unprocessedShards.Remove(connectedShard);
                }
            }
        }
    }

```