Need help converting the following code into one using direct port manipulatio

Following is the program for scanning a keyboard for MIDI transfer.
At present the code works fine, but it could be faster.
I need help to use direct port manipulation inside the for loop.

boolean keypressed[6][6]; //for storing key states
int midinote[6][6] ={ 60 ,61 ,62 ,63 ,64 ,65 
                     ,66 ,67 ,68 ,69 ,70 ,71 
                     ,72 ,73 ,74 ,75 ,76 ,77 
                     ,78 ,79 ,80 ,81 ,82 ,83 
                     ,84 ,85 ,86 ,87 ,88 ,89 
                     ,90 ,91 ,92 ,93 ,94 ,95  }; //code for various midi notes C3 to C6


void setup() {

  Serial.begin(38400); 
  for(int i=0; i<6; i++){
    pinMode(i+2,OUTPUT);
    digitalWrite(i+8,HIGH);
  }
  for(int i=0; i<6; i++){
    pinMode(i+8,INPUT);
    digitalWrite(i+8,HIGH);
  }
  for (int i=0; i<6; i++){
    for(int j=0; j<6; j++){
      keypressed[i][j] = false;
    }
  }
}

void loop() {

  for(int i=0; i<6; i++){
    digitalWrite(i+2, LOW);
    for(int j =0; j<6; j++){
      if ((digitalRead(j+8) == LOW) && !keypressed[i][j]){
         Serial.write(0x91);
         Serial.write(midinote[i][j]);
         Serial.write(127); 
         keypressed[i][j] = true;
        }
        if ((digitalRead(j+8) == HIGH) && keypressed[i][j]){
         Serial.write(0x91);
         Serial.write(midinote[i][j]);
         Serial.write(0);
         keypressed[i][j] =false;
      }  
    }
    digitalWrite(i+2, HIGH);
  }
  
}

What evidence do you have that it needs to be faster? Are you missing key presses?

depending on what hardware you are using, you can figure out what port/bit combination represents each of your pins represent and use them directly.

I'm just exploring possibilities for the sake of learning.

I know about basic port manipulation. I don't know how to use then inside a loop and by some way use the loop variable to call them just like digitalWrite()

First you’ll need to arrange for all the rows/columns of your keyboard to be on pins from the same ports (rows on one port, columns on another).
Otherwise there’s little to no point trying.

Already done that D2 to D7 are PORTD and D8 to D13 are PORTB