How efficient is this code for midi keyboard scanning?

Firstly, I have no prior experience related to any midi projects, nay keyboard matrix scanning projects. I came up with this code on my own, so please point out all and any pitfalls and options to improve this program.

byte portd[] = {4,8,16,32,64,128};
boolean keypressed[6][6]; //for storing key states
byte 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
byte i,j;

int main (void) {
  
  init();
  
  Serial.begin(38400); 
  
   DDRD |= 0b11111100;
   PORTB &= 0b0000001;
  
  DDRB &= 0b11000000;
  PORTB |= 0b00111111;
  
  for (i=0; i<6; i++){
    for(j=0; j<6; j++){
      keypressed[i][j] = false;
    }
  }


while(1) {
  
  for(i=0; i<6; i++){
    PORTD &= ~portd[i];
    for(j =0; j<6; j++){
      if (((PINB & (1<<j)) == 0) && !keypressed[i][j]){
         Serial.write(0x91);
         Serial.write(midinote[i][j]);
         Serial.write(127); 
         keypressed[i][j] = true;
        }
        if (((PINB & (1<<j)) != 0) && keypressed[i][j]){
         Serial.write(0x91);
         Serial.write(midinote[i][j]);
         Serial.write(0);
         keypressed[i][j] =false;
      }  
    }
   PORTD |= portd[i];
  }
  
}
return 0;
}

What makes you think it is inefficient?

Why do you have array...

byte portb[] = {0,2,4,8,16,32};

...for the port pin bit masks, and then not use it...

if (((PINB & (1<<j)) == 0) && !keypressed[i][j]){
if (((PINB & (1<<j)) != 0) && keypressed[i][j]){

Also your bit mask for the first pin in PORTB is incorrect (0 when presumably it should be 1).

Does you keypad have diodes? If not you will have a short if you press more than one key at a time.

The correct way to drive a matrix keypad is to set all "output" pins (e.g. rows) as INPUT_PULLUP, then set ONE row pin at at time as OUTPUT LOW, test the "input" pins (e.g. columns) to see if a key was pressed on that row, then return the row pin the INPUT_PULLUP.

Why this sudden obsession with "efficiency", especially of MIDI keyboard scanning? There was another post worrying about this recently. Homework assignment?