mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 21:51:50 +00:00 
			
		
		
		
	GH-111843: Tier 2 exponential backoff (GH-111850)
This commit is contained in:
		
							parent
							
								
									25c4956488
								
							
						
					
					
						commit
						34a03e951b
					
				
					 5 changed files with 47 additions and 14 deletions
				
			
		
							
								
								
									
										23
									
								
								Python/generated_cases.c.h
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										23
									
								
								Python/generated_cases.c.h
									
										
									
										generated
									
									
									
								
							|  | @ -3409,10 +3409,12 @@ | |||
|             JUMPBY(-oparg); | ||||
|             #if ENABLE_SPECIALIZATION | ||||
|             this_instr[1].cache += (1 << OPTIMIZER_BITS_IN_COUNTER); | ||||
|             if (this_instr[1].cache > tstate->interp->optimizer_backedge_threshold && | ||||
|                 // Double-check that the opcode isn't instrumented or something:
 | ||||
|                 this_instr->op.code == JUMP_BACKWARD) | ||||
|             { | ||||
|             /* We are using unsigned values, but we really want signed values, so
 | ||||
|              * do the 2s complement comparison manually */ | ||||
|             uint16_t ucounter = this_instr[1].cache + (1 << 15); | ||||
|             uint16_t threshold = tstate->interp->optimizer_backedge_threshold + (1 << 15); | ||||
|             // Double-check that the opcode isn't instrumented or something:
 | ||||
|             if (ucounter > threshold && this_instr->op.code == JUMP_BACKWARD) { | ||||
|                 OPT_STAT_INC(attempts); | ||||
|                 int optimized = _PyOptimizer_BackEdge(frame, this_instr, next_instr, stack_pointer); | ||||
|                 if (optimized < 0) goto error; | ||||
|  | @ -3420,8 +3422,19 @@ | |||
|                     // Rewind and enter the executor:
 | ||||
|                     assert(this_instr->op.code == ENTER_EXECUTOR); | ||||
|                     next_instr = this_instr; | ||||
|                     this_instr[1].cache &= ((1 << OPTIMIZER_BITS_IN_COUNTER) - 1); | ||||
|                 } | ||||
|                 else { | ||||
|                     int backoff = this_instr[1].cache & ((1 << OPTIMIZER_BITS_IN_COUNTER) - 1); | ||||
|                     if (backoff < MINIMUM_TIER2_BACKOFF) { | ||||
|                         backoff = MINIMUM_TIER2_BACKOFF; | ||||
|                     } | ||||
|                     else if (backoff < 15 - OPTIMIZER_BITS_IN_COUNTER) { | ||||
|                         backoff++; | ||||
|                     } | ||||
|                     assert(backoff <= 15 - OPTIMIZER_BITS_IN_COUNTER); | ||||
|                     this_instr[1].cache = ((1 << 16) - ((1 << OPTIMIZER_BITS_IN_COUNTER) << backoff)) | backoff; | ||||
|                 } | ||||
|                 this_instr[1].cache &= ((1 << OPTIMIZER_BITS_IN_COUNTER) - 1); | ||||
|             } | ||||
|             #endif  /* ENABLE_SPECIALIZATION */ | ||||
|             DISPATCH(); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Mark Shannon
						Mark Shannon