The purpose of fasting before a procedure involving anesthesia is to avoid aspiration of stomach contents, not anything related to drug efficacy. Your anesthesiologist/physician/dentist/nurse wants you to have an empty stomach so you don't regurgitate and then inhale food while your reflexes are suppressed.
Fasting procedures can depend on the specific patient and operation, so it's important for patients to follow those instructions.
Anesthetic drugs are typically given intravenously or are inhaled when used in surgical procedures, not orally, so stomach contents don't matter for the drug effects.
From the ASA guidelines (citation below):
The purposes of these guidelines are to provide direction for clinical practice related to preoperative fasting and the use of pharmacologic agents to reduce the risk of pulmonary aspiration and to reduce the severity of complications related to perioperative pulmonary aspiration. Clinical practice includes, but is not limited to, withholding of liquids and solids for specified time periods before surgery and prescribing pharmacologic agents to reduce gastric volume and acidity.
Complications of aspiration include, but are not limited to, aspiration pneumonia, respiratory compromise, and related morbidities.
Practice Guidelines for Preoperative Fasting and the Use of Pharmacologic Agents to Reduce the Risk of Pulmonary Aspiration: Application to Healthy Patients Undergoing Elective Procedures: An Updated Report by the American Society of Anesthesiologists Task Force on Preoperative Fasting and the Use of Pharmacologic Agents to Reduce the Risk of Pulmonary Aspiration. Anesthesiology 2017;126(3):376-393. doi: https://doi.org/10.1097/ALN.0000000000001452.