• About TC
  • Affiliate Disclaimer
  • Privacy Policy
  • TOS
  • Contact
Tuesday, September 9, 2025
Techcratic
No Result
View All Result
  • AI
    Artificial Intelligence

    How Yichao “Peak” Ji became a global AI app hitmaker

    Artificial Intelligence

    How Amazon Finance built an AI assistant using Amazon Bedrock and Amazon Kendra to…

    Artificial Intelligence

    5 Reasons Why Vibe Coding Threatens Secure Data App Development

    Artificial Intelligence

    Unlocking the future of professional services: How Proofpoint uses Amazon Q Business

    Artificial Intelligence

    Exploring the Real-Time Race Track with Amazon Nova

    Artificial Intelligence

    Accelerating HPC and AI research in universities with Amazon SageMaker HyperPod

    Artificial Intelligence

    Building the AI-enabled enterprise of the future

    Artificial Intelligence

    From JSON to Dashboard: Visualizing DuckDB Queries in Streamlit with Plotly

    Artificial Intelligence

    The “Super Weight:” How Even a Single Parameter can Determine a Large Language Model’s…

  • Apple
    Spigen’s iPhone 17 Pro Max clear cases give Apple logo space

    Spigen’s iPhone 17 Pro Max clear cases give Apple logo space

    This is Apple’s new Crossbody Strap accessory for iPhone

    This is Apple’s new Crossbody Strap accessory for iPhone

    Apple launches new TechWoven material for iPhone 17 cases

    Apple launches new TechWoven material for iPhone 17 cases

    Apple loses to HP in ACSI personal computer satisfaction survey

    Apple loses to HP in ACSI personal computer satisfaction survey

    Skipping the iPhone 17? This M4 MacBook Pro with 24GB of RAM is just $1,399

    Skipping the iPhone 17? This M4 MacBook Pro with 24GB of RAM is just $1,399

    This one new feature might finally bring me back to the Mac in 2025

    Next year’s MacBook Pro redesign with OLED gets timeline update

    OWC dock brings Thunderbolt 5 & 20GbE speed to Mac & PC

    OWC dock brings Thunderbolt 5 & 20GbE speed to Mac & PC

    Another Plex data breach sees company urge users to change their password

    Another Plex data breach sees company urge users to change their password

    9 ways to use your iPhone’s USB-C port

    9 uses for your iPhone’s USB-C port other than fast charging

  • ComputerWorld
    Intel announces leadership overhaul, underscoring long road to recovery

    Intel announces leadership overhaul, underscoring long road to recovery

    Atlassian exec details the $610M Browser Company acquisition

    Atlassian exec details the $610M Browser Company acquisition

    Uber turns drivers into AI data labelers in India pilot

    Uber turns drivers into AI data labelers in India pilot

    Tech employment is a mixed bag, selective hiring marks a shift

    Tech employment is a mixed bag, selective hiring marks a shift

    Why generative AI projects fail

    Why generative AI projects fail

    Here are the top AI certifications that will get you hired and promoted

    Here are the top AI certifications that will get you hired and promoted

    Relief for European Commission as court upholds EU Data Privacy Framework agreement with…

    Relief for European Commission as court upholds EU Data Privacy Framework agreement with…

    Bill Gates’ early BASIC code for MOS 6502 released as open source

    Bill Gates’ early BASIC code for MOS 6502 released as open source

    Apple may twin with Gemini for AI as iPhone 17 looms

    Apple may twin with Gemini for AI as iPhone 17 looms

  • Gaming
    HUGE FNAF NEWS!! Movie trailer, Security breach DLC, Help wanted VR 2

    HUGE FNAF NEWS!! Movie trailer, Security breach DLC, Help wanted VR 2

    Serve and Protect: Detect 6 Violations | RoboCop Rogue City

    Serve and Protect: Detect 6 Violations | RoboCop Rogue City

    THYMESIA | 16 MINUTES OF GAMEPLAY | [1080P 60 FPS]

    THYMESIA | 16 MINUTES OF GAMEPLAY | [1080P 60 FPS]

    There’s another golden RTX 5090 made of over 1,000x more gold than the first, and I’m pleased to say it’s absolutely hideous

    XFX says its ‘V3’ Radeon RX 9060 XT GPUs with Samsung GDDR6 run much cooler and quieter than previous models with SK Hynix memory

    Starship Troopers Extermination: Last Man Standing

    Starship Troopers Extermination: Last Man Standing

    Watch The PC Gamer Streamer Showdown live today on Twitch

    Watch The PC Gamer Streamer Showdown live today on Twitch

    As Dusk Falls Pt.2: WHO THE F IS BRUCE?!

    As Dusk Falls Pt.2: WHO THE F IS BRUCE?!

    Intel reshuffle puts engineering and ‘a new custom silicon business’ in the spotlight but also ends a 30-year career at Intel for Product CEO Michelle Johnston Holthaus

    Intel reshuffle puts engineering and ‘a new custom silicon business’ in the spotlight but also ends a 30-year career at Intel for Product CEO Michelle Johnston Holthaus

    DIABLO 4 SEASON 1 REVIEW

    DIABLO 4 SEASON 1 REVIEW

  • Retro Rewind
    Retro Rewind: Game Players Issue 80 Magazine January 1996

    Retro Rewind: Game Players Issue 80 Magazine January 1996

    Retro Rewind: Video Game Trader Winter 2014

    Retro Rewind: Video Game Trader Winter 2014

    Retro Rewind: Electronic Games April 1995

    Retro Rewind: Electronic Games April 1995

    Retro Rewind: Electronic Gaming Monthly Magazine Number 55 February 1994

    Retro Rewind: Electronic Gaming Monthly Magazine Number 57 April 1994

    Retro Rewind: Blast from the Past – 35 Iconic Commercials of 1988!

    Retro Rewind: Blast from the Past – 35 Iconic Commercials of 1988!

    Retro Rewind: PC World Magazine August 1998

    Retro Rewind: PC World Magazine August 1998

    Retro Rewind: Computer Shopper Magazine September 1997

    Retro Rewind: Computer Shopper Magazine September 1997

    Retro Rewind: PC Magazine December 2015

    Retro Rewind: PC Magazine December 2015

    Retro Rewind: EDGE Magazine RETRO #1: The Guide to Classic Videogame Playing and Collecting

    Retro Rewind: EDGE Magazine RETRO #1: The Guide to Classic Videogame Playing and Collecting

  • Tech Art
    SUNY New Paltz Presents “Composium,” a Series of Events Exploring Sustainability in the Arts

    SUNY New Paltz Presents “Composium,” a Series of Events Exploring Sustainability in the Arts

    Color Theory Basics for Digital Painters

    Color Theory Basics for Digital Painters

    3D Cube design in Illusion – 3D Optical Illusion Explained in illustrator 2025

    3D Cube design in Illusion – 3D Optical Illusion Explained in illustrator 2025

    Don’t make these shading mistakes

    Don’t make these shading mistakes

    AR Car Showroom App Review – Augmented Reality Vehicle Showcase

    AR Car Showroom App Review – Augmented Reality Vehicle Showcase

    Infinite design tutorial (vector art) step by step | ultimate focus tamil

    Infinite design tutorial (vector art) step by step | ultimate focus tamil

    (877) Awesome Peach and Gold Spray Paint Mixed Media Pour

    (877) Awesome Peach and Gold Spray Paint Mixed Media Pour

    Kirito's Elucidator (Sword Art Online) – MAN AT ARMS

    Kirito's Elucidator (Sword Art Online) – MAN AT ARMS

    The Overlooked Link Between Web Design and Search Success

    The Overlooked Link Between Web Design and Search Success

  • Tech Deals
    ASRock AMD Radeon RX 9070 XT Steel Legend 16GB, Boost Clock Up to 2970 MHz / 20 Gbps,…

    ASRock AMD Radeon RX 9070 XT Steel Legend 16GB, Boost Clock Up to 2970 MHz / 20 Gbps,…

    DUMOS L Shaped Desk Computer Gaming Corner Table 50 Inch Home Office Writing Student…

    DUMOS L Shaped Desk Computer Gaming Corner Table 50 Inch Home Office Writing Student…

    Wired Portable 60% Mechanical Feeling Gaming Keyboard,RGB LED Backlit Compact 68 Keys…

    Wired Portable 60% Mechanical Feeling Gaming Keyboard,RGB LED Backlit Compact 68 Keys…

    Flying Stone Game Set Biseokchigi – Traditional Korean Folk Game – Fun Kit for Family…

    Flying Stone Game Set Biseokchigi – Traditional Korean Folk Game – Fun Kit for Family…

    Avalanche – Retro-2600/2600+/7800/7800+

    Avalanche – Retro-2600/2600+/7800/7800+

    TOSHIBA AC25CEW-BS Large 6-Slice Convection Toaster Oven Countertop, 10-In-One with…

    TOSHIBA AC25CEW-BS Large 6-Slice Convection Toaster Oven Countertop, 10-In-One with…

    Toshiba Canvio Advance 1TB Portable External Hard Drive USB 3.0, Black – HDTCA10XK3AA

    Toshiba Canvio Advance 1TB Portable External Hard Drive USB 3.0, Black – HDTCA10XK3AA

    SanDisk Professional 1TB PRO-Blade SSD Mag – Portable & Modular NVMe SSD Mag,…

    SanDisk Professional 1TB PRO-Blade SSD Mag – Portable & Modular NVMe SSD Mag,…

    Samsung Galaxy A12, Unlocked Smartphone, Android Cell Phone, Multi-Camera System,…

    Samsung Galaxy A12, Unlocked Smartphone, Android Cell Phone, Multi-Camera System,…

  • Techs Got To Eat
    Spicy Chickpea Shakshuka Mug: 5-Minute Vegetarian Fuel

    Spicy Chickpea Shakshuka Mug: 5-Minute Vegetarian Fuel

    Bacon & Spinach Mug Quiche: 3-Minute Gourmet Breakfast

    Bacon & Spinach Mug Quiche: 3-Minute Gourmet Breakfast

    Cheesy Broccoli Rice Mug: 5-Minute Super Comfort Food

    Cheesy Broccoli Rice Mug: 5-Minute Super Comfort Food

    Top 10 Vegetarian Recipes for 2025: Easy and Nutritious Meals for Busy People

    Top 10 Vegetarian Recipes for 2025: Easy and Nutritious Meals for Busy People

    Bacon Mug Lasagna: 5-Minute Microwave Meat Lover’s Dream

    Bacon Mug Lasagna: 5-Minute Microwave Meat Lover’s Dream

    Bacon Fried Rice Mug: 5-Minute Microwave Meal

    Bacon Fried Rice Mug: 5-Minute Microwave Meal

    Bacon & Cheddar Mug Biscuit: 2-Minute Savory Comfort

    Bacon & Cheddar Mug Biscuit: 2-Minute Savory Comfort

    Loaded Bacon Cheesy Potato Mug: 5-Minute Comfort Food

    Loaded Bacon Cheesy Potato Mug: 5-Minute Comfort Food

    Peanut Butter Banana Mug Muffin: 5-Minute Protein Snack

    Peanut Butter Banana Mug Muffin: 5-Minute Protein Snack

  • Tesla
    Coverado Car Seat Covers Full Set, Seat Covers for Cars, Front Seat Covers and Back Seat…

    Coverado Car Seat Covers Full Set, Seat Covers for Cars, Front Seat Covers and Back Seat…

    Pack of 4 Car Floor Mat Clips, Durable Foot Pad Buckle Set, Interior Floor Mat Safety…

    Pack of 4 Car Floor Mat Clips, Durable Foot Pad Buckle Set, Interior Floor Mat Safety…

    Carwiner Center Console Cover for Tesla Model 3 Model Y, PU Leather Armrest Box Cushion…

    Carwiner Center Console Cover for Tesla Model 3 Model Y, PU Leather Armrest Box Cushion…

    Tesla gives up on Cybertruck wireless charging

    DREIEYECAM Dash cam for Tesla Model S AP1 Full HD 1080P WiFi G-Sensor WDR is Auto Video…

    DREIEYECAM Dash cam for Tesla Model S AP1 Full HD 1080P WiFi G-Sensor WDR is Auto Video…

    Car Sun Visor Organizer, Soft Leather Surface Eyeglasses Note Card Holder Car Storage…

    Car Sun Visor Organizer, Soft Leather Surface Eyeglasses Note Card Holder Car Storage…

    Tesla unveils Megablock and Megapack 3: more power and energy deployed faster

    Tesla unveils Megablock and Megapack 3: more power and energy deployed faster

    Center Console Organizer Tray for Tesla Model Y 2024-2020(Not Fit 2024 2025Model Y…

    Center Console Organizer Tray for Tesla Model Y 2024-2020(Not Fit 2024 2025Model Y…

    Tesla employees try to oust Elon, new Volvo, and Micah’s close call

    Tesla market share drops, Mercedes, BMW, and VW drop new EVs

  • UFO
    Mototo 6 PCS 63 Inch Giant Inflatable Alien 31.5 Inch Jumbo Blow Up Alien Green Inflatable Toy for Space Party Decoration UFO Theme Spaceship Party Birthday Halloween Easter Christmas Home

    Mototo 6 PCS 63 Inch Giant Inflatable Alien 31.5 Inch Jumbo Blow Up Alien Green Inflatable Toy for Space Party Decoration UFO Theme Spaceship Party Birthday Halloween Easter Christmas Home

    UFO evidence finally revealed!

    UFO evidence finally revealed!

    Alien Invasion: RPG Idle Space | CrazyLabs

    Alien Invasion: RPG Idle Space | CrazyLabs

    Hangover Terrace

    Hangover Terrace

    Alien Birthday Party Decorations Door Curtain with Foil Fringe Tinsel Spacecraft Flying Saucer Spaceship Hanging Banner for Alien Halloween Party(Fluorescent Yellow)

    Alien Birthday Party Decorations Door Curtain with Foil Fringe Tinsel Spacecraft Flying Saucer Spaceship Hanging Banner for Alien Halloween Party(Fluorescent Yellow)

    #most #famous #encounters of #3types with #extraterrestrial in #history P.1.3 –

    #most #famous #encounters of #3types with #extraterrestrial in #history P.1.3 –

    ANCIENT ALIEN IMAGES FOUND | The Proof Is Out There | #Shorts

    ANCIENT ALIEN IMAGES FOUND | The Proof Is Out There | #Shorts

    #love #truth

    #love #truth

    Flying Saucer UFO Poster Print, Sci-fi Gift, UFO Wall Art, Alien Spacecraft, Area 51 Art, Nerd Geek Gift, Space Art Vintage Paper (11 inch x 14 inch)

    Flying Saucer UFO Poster Print, Sci-fi Gift, UFO Wall Art, Alien Spacecraft, Area 51 Art, Nerd Geek Gift, Space Art Vintage Paper (11 inch x 14 inch)

  • AI
    Artificial Intelligence

    How Yichao “Peak” Ji became a global AI app hitmaker

    Artificial Intelligence

    How Amazon Finance built an AI assistant using Amazon Bedrock and Amazon Kendra to…

    Artificial Intelligence

    5 Reasons Why Vibe Coding Threatens Secure Data App Development

    Artificial Intelligence

    Unlocking the future of professional services: How Proofpoint uses Amazon Q Business

    Artificial Intelligence

    Exploring the Real-Time Race Track with Amazon Nova

    Artificial Intelligence

    Accelerating HPC and AI research in universities with Amazon SageMaker HyperPod

    Artificial Intelligence

    Building the AI-enabled enterprise of the future

    Artificial Intelligence

    From JSON to Dashboard: Visualizing DuckDB Queries in Streamlit with Plotly

    Artificial Intelligence

    The “Super Weight:” How Even a Single Parameter can Determine a Large Language Model’s…

  • Apple
    Spigen’s iPhone 17 Pro Max clear cases give Apple logo space

    Spigen’s iPhone 17 Pro Max clear cases give Apple logo space

    This is Apple’s new Crossbody Strap accessory for iPhone

    This is Apple’s new Crossbody Strap accessory for iPhone

    Apple launches new TechWoven material for iPhone 17 cases

    Apple launches new TechWoven material for iPhone 17 cases

    Apple loses to HP in ACSI personal computer satisfaction survey

    Apple loses to HP in ACSI personal computer satisfaction survey

    Skipping the iPhone 17? This M4 MacBook Pro with 24GB of RAM is just $1,399

    Skipping the iPhone 17? This M4 MacBook Pro with 24GB of RAM is just $1,399

    This one new feature might finally bring me back to the Mac in 2025

    Next year’s MacBook Pro redesign with OLED gets timeline update

    OWC dock brings Thunderbolt 5 & 20GbE speed to Mac & PC

    OWC dock brings Thunderbolt 5 & 20GbE speed to Mac & PC

    Another Plex data breach sees company urge users to change their password

    Another Plex data breach sees company urge users to change their password

    9 ways to use your iPhone’s USB-C port

    9 uses for your iPhone’s USB-C port other than fast charging

  • ComputerWorld
    Intel announces leadership overhaul, underscoring long road to recovery

    Intel announces leadership overhaul, underscoring long road to recovery

    Atlassian exec details the $610M Browser Company acquisition

    Atlassian exec details the $610M Browser Company acquisition

    Uber turns drivers into AI data labelers in India pilot

    Uber turns drivers into AI data labelers in India pilot

    Tech employment is a mixed bag, selective hiring marks a shift

    Tech employment is a mixed bag, selective hiring marks a shift

    Why generative AI projects fail

    Why generative AI projects fail

    Here are the top AI certifications that will get you hired and promoted

    Here are the top AI certifications that will get you hired and promoted

    Relief for European Commission as court upholds EU Data Privacy Framework agreement with…

    Relief for European Commission as court upholds EU Data Privacy Framework agreement with…

    Bill Gates’ early BASIC code for MOS 6502 released as open source

    Bill Gates’ early BASIC code for MOS 6502 released as open source

    Apple may twin with Gemini for AI as iPhone 17 looms

    Apple may twin with Gemini for AI as iPhone 17 looms

  • Gaming
    HUGE FNAF NEWS!! Movie trailer, Security breach DLC, Help wanted VR 2

    HUGE FNAF NEWS!! Movie trailer, Security breach DLC, Help wanted VR 2

    Serve and Protect: Detect 6 Violations | RoboCop Rogue City

    Serve and Protect: Detect 6 Violations | RoboCop Rogue City

    THYMESIA | 16 MINUTES OF GAMEPLAY | [1080P 60 FPS]

    THYMESIA | 16 MINUTES OF GAMEPLAY | [1080P 60 FPS]

    There’s another golden RTX 5090 made of over 1,000x more gold than the first, and I’m pleased to say it’s absolutely hideous

    XFX says its ‘V3’ Radeon RX 9060 XT GPUs with Samsung GDDR6 run much cooler and quieter than previous models with SK Hynix memory

    Starship Troopers Extermination: Last Man Standing

    Starship Troopers Extermination: Last Man Standing

    Watch The PC Gamer Streamer Showdown live today on Twitch

    Watch The PC Gamer Streamer Showdown live today on Twitch

    As Dusk Falls Pt.2: WHO THE F IS BRUCE?!

    As Dusk Falls Pt.2: WHO THE F IS BRUCE?!

    Intel reshuffle puts engineering and ‘a new custom silicon business’ in the spotlight but also ends a 30-year career at Intel for Product CEO Michelle Johnston Holthaus

    Intel reshuffle puts engineering and ‘a new custom silicon business’ in the spotlight but also ends a 30-year career at Intel for Product CEO Michelle Johnston Holthaus

    DIABLO 4 SEASON 1 REVIEW

    DIABLO 4 SEASON 1 REVIEW

  • Retro Rewind
    Retro Rewind: Game Players Issue 80 Magazine January 1996

    Retro Rewind: Game Players Issue 80 Magazine January 1996

    Retro Rewind: Video Game Trader Winter 2014

    Retro Rewind: Video Game Trader Winter 2014

    Retro Rewind: Electronic Games April 1995

    Retro Rewind: Electronic Games April 1995

    Retro Rewind: Electronic Gaming Monthly Magazine Number 55 February 1994

    Retro Rewind: Electronic Gaming Monthly Magazine Number 57 April 1994

    Retro Rewind: Blast from the Past – 35 Iconic Commercials of 1988!

    Retro Rewind: Blast from the Past – 35 Iconic Commercials of 1988!

    Retro Rewind: PC World Magazine August 1998

    Retro Rewind: PC World Magazine August 1998

    Retro Rewind: Computer Shopper Magazine September 1997

    Retro Rewind: Computer Shopper Magazine September 1997

    Retro Rewind: PC Magazine December 2015

    Retro Rewind: PC Magazine December 2015

    Retro Rewind: EDGE Magazine RETRO #1: The Guide to Classic Videogame Playing and Collecting

    Retro Rewind: EDGE Magazine RETRO #1: The Guide to Classic Videogame Playing and Collecting

  • Tech Art
    SUNY New Paltz Presents “Composium,” a Series of Events Exploring Sustainability in the Arts

    SUNY New Paltz Presents “Composium,” a Series of Events Exploring Sustainability in the Arts

    Color Theory Basics for Digital Painters

    Color Theory Basics for Digital Painters

    3D Cube design in Illusion – 3D Optical Illusion Explained in illustrator 2025

    3D Cube design in Illusion – 3D Optical Illusion Explained in illustrator 2025

    Don’t make these shading mistakes

    Don’t make these shading mistakes

    AR Car Showroom App Review – Augmented Reality Vehicle Showcase

    AR Car Showroom App Review – Augmented Reality Vehicle Showcase

    Infinite design tutorial (vector art) step by step | ultimate focus tamil

    Infinite design tutorial (vector art) step by step | ultimate focus tamil

    (877) Awesome Peach and Gold Spray Paint Mixed Media Pour

    (877) Awesome Peach and Gold Spray Paint Mixed Media Pour

    Kirito's Elucidator (Sword Art Online) – MAN AT ARMS

    Kirito's Elucidator (Sword Art Online) – MAN AT ARMS

    The Overlooked Link Between Web Design and Search Success

    The Overlooked Link Between Web Design and Search Success

  • Tech Deals
    ASRock AMD Radeon RX 9070 XT Steel Legend 16GB, Boost Clock Up to 2970 MHz / 20 Gbps,…

    ASRock AMD Radeon RX 9070 XT Steel Legend 16GB, Boost Clock Up to 2970 MHz / 20 Gbps,…

    DUMOS L Shaped Desk Computer Gaming Corner Table 50 Inch Home Office Writing Student…

    DUMOS L Shaped Desk Computer Gaming Corner Table 50 Inch Home Office Writing Student…

    Wired Portable 60% Mechanical Feeling Gaming Keyboard,RGB LED Backlit Compact 68 Keys…

    Wired Portable 60% Mechanical Feeling Gaming Keyboard,RGB LED Backlit Compact 68 Keys…

    Flying Stone Game Set Biseokchigi – Traditional Korean Folk Game – Fun Kit for Family…

    Flying Stone Game Set Biseokchigi – Traditional Korean Folk Game – Fun Kit for Family…

    Avalanche – Retro-2600/2600+/7800/7800+

    Avalanche – Retro-2600/2600+/7800/7800+

    TOSHIBA AC25CEW-BS Large 6-Slice Convection Toaster Oven Countertop, 10-In-One with…

    TOSHIBA AC25CEW-BS Large 6-Slice Convection Toaster Oven Countertop, 10-In-One with…

    Toshiba Canvio Advance 1TB Portable External Hard Drive USB 3.0, Black – HDTCA10XK3AA

    Toshiba Canvio Advance 1TB Portable External Hard Drive USB 3.0, Black – HDTCA10XK3AA

    SanDisk Professional 1TB PRO-Blade SSD Mag – Portable & Modular NVMe SSD Mag,…

    SanDisk Professional 1TB PRO-Blade SSD Mag – Portable & Modular NVMe SSD Mag,…

    Samsung Galaxy A12, Unlocked Smartphone, Android Cell Phone, Multi-Camera System,…

    Samsung Galaxy A12, Unlocked Smartphone, Android Cell Phone, Multi-Camera System,…

  • Techs Got To Eat
    Spicy Chickpea Shakshuka Mug: 5-Minute Vegetarian Fuel

    Spicy Chickpea Shakshuka Mug: 5-Minute Vegetarian Fuel

    Bacon & Spinach Mug Quiche: 3-Minute Gourmet Breakfast

    Bacon & Spinach Mug Quiche: 3-Minute Gourmet Breakfast

    Cheesy Broccoli Rice Mug: 5-Minute Super Comfort Food

    Cheesy Broccoli Rice Mug: 5-Minute Super Comfort Food

    Top 10 Vegetarian Recipes for 2025: Easy and Nutritious Meals for Busy People

    Top 10 Vegetarian Recipes for 2025: Easy and Nutritious Meals for Busy People

    Bacon Mug Lasagna: 5-Minute Microwave Meat Lover’s Dream

    Bacon Mug Lasagna: 5-Minute Microwave Meat Lover’s Dream

    Bacon Fried Rice Mug: 5-Minute Microwave Meal

    Bacon Fried Rice Mug: 5-Minute Microwave Meal

    Bacon & Cheddar Mug Biscuit: 2-Minute Savory Comfort

    Bacon & Cheddar Mug Biscuit: 2-Minute Savory Comfort

    Loaded Bacon Cheesy Potato Mug: 5-Minute Comfort Food

    Loaded Bacon Cheesy Potato Mug: 5-Minute Comfort Food

    Peanut Butter Banana Mug Muffin: 5-Minute Protein Snack

    Peanut Butter Banana Mug Muffin: 5-Minute Protein Snack

  • Tesla
    Coverado Car Seat Covers Full Set, Seat Covers for Cars, Front Seat Covers and Back Seat…

    Coverado Car Seat Covers Full Set, Seat Covers for Cars, Front Seat Covers and Back Seat…

    Pack of 4 Car Floor Mat Clips, Durable Foot Pad Buckle Set, Interior Floor Mat Safety…

    Pack of 4 Car Floor Mat Clips, Durable Foot Pad Buckle Set, Interior Floor Mat Safety…

    Carwiner Center Console Cover for Tesla Model 3 Model Y, PU Leather Armrest Box Cushion…

    Carwiner Center Console Cover for Tesla Model 3 Model Y, PU Leather Armrest Box Cushion…

    Tesla gives up on Cybertruck wireless charging

    DREIEYECAM Dash cam for Tesla Model S AP1 Full HD 1080P WiFi G-Sensor WDR is Auto Video…

    DREIEYECAM Dash cam for Tesla Model S AP1 Full HD 1080P WiFi G-Sensor WDR is Auto Video…

    Car Sun Visor Organizer, Soft Leather Surface Eyeglasses Note Card Holder Car Storage…

    Car Sun Visor Organizer, Soft Leather Surface Eyeglasses Note Card Holder Car Storage…

    Tesla unveils Megablock and Megapack 3: more power and energy deployed faster

    Tesla unveils Megablock and Megapack 3: more power and energy deployed faster

    Center Console Organizer Tray for Tesla Model Y 2024-2020(Not Fit 2024 2025Model Y…

    Center Console Organizer Tray for Tesla Model Y 2024-2020(Not Fit 2024 2025Model Y…

    Tesla employees try to oust Elon, new Volvo, and Micah’s close call

    Tesla market share drops, Mercedes, BMW, and VW drop new EVs

  • UFO
    Mototo 6 PCS 63 Inch Giant Inflatable Alien 31.5 Inch Jumbo Blow Up Alien Green Inflatable Toy for Space Party Decoration UFO Theme Spaceship Party Birthday Halloween Easter Christmas Home

    Mototo 6 PCS 63 Inch Giant Inflatable Alien 31.5 Inch Jumbo Blow Up Alien Green Inflatable Toy for Space Party Decoration UFO Theme Spaceship Party Birthday Halloween Easter Christmas Home

    UFO evidence finally revealed!

    UFO evidence finally revealed!

    Alien Invasion: RPG Idle Space | CrazyLabs

    Alien Invasion: RPG Idle Space | CrazyLabs

    Hangover Terrace

    Hangover Terrace

    Alien Birthday Party Decorations Door Curtain with Foil Fringe Tinsel Spacecraft Flying Saucer Spaceship Hanging Banner for Alien Halloween Party(Fluorescent Yellow)

    Alien Birthday Party Decorations Door Curtain with Foil Fringe Tinsel Spacecraft Flying Saucer Spaceship Hanging Banner for Alien Halloween Party(Fluorescent Yellow)

    #most #famous #encounters of #3types with #extraterrestrial in #history P.1.3 –

    #most #famous #encounters of #3types with #extraterrestrial in #history P.1.3 –

    ANCIENT ALIEN IMAGES FOUND | The Proof Is Out There | #Shorts

    ANCIENT ALIEN IMAGES FOUND | The Proof Is Out There | #Shorts

    #love #truth

    #love #truth

    Flying Saucer UFO Poster Print, Sci-fi Gift, UFO Wall Art, Alien Spacecraft, Area 51 Art, Nerd Geek Gift, Space Art Vintage Paper (11 inch x 14 inch)

    Flying Saucer UFO Poster Print, Sci-fi Gift, UFO Wall Art, Alien Spacecraft, Area 51 Art, Nerd Geek Gift, Space Art Vintage Paper (11 inch x 14 inch)

No Result
View All Result
Techcratic
No Result
View All Result
Home Hacker News

Optimizing a Math Expression Parser in Rust

Hacker News by Hacker News
July 10, 2025
in Hacker News
Reading Time: 54 mins read
121
A A
0

2025-07-10 05:27:00
rpallas.xyz

Monday. June 30, 2025 – 44 mins

Table of contents

  1. Baseline implementation (43.1 s)
    1. How it works
    2. Parser Example: (1 + 2) – 3
    3. It works! But we can do better
  2. Optimizations for speed and memory
    1. Optimization 1: Do not allocate a Vector when tokenizing (43.1 s → 6.45 s, –85% improvement)
    2. Optimization 2: Zero allocations — parse directly from the input bytes (6.45 s → 3.68 s, –43% improvement)
    3. Optimization 3: Do not use Peekable (3.68 s → 3.21 s, –13% improvement)
    4. Optimization 4: Multithreading and SIMD (3.21 s → 2.21 s, –31% improvement)
    5. Optimization 5: Memory‑mapped I/O (2.21 s → 0.98 s, –56% improvement)
  3. Conclusion

In a previous post I explored how to optimize file parsing for max speed. This time, we’ll look at a different, self-contained problem: writing a math expression parser in Rust, and making it as fast and memory-efficient as possible.

Let’s say we want to parse simple math expressions with addition, subtraction, and parentheses. For example:

4 + 5 + 2 - 1       => 10
(4 + 5) - (2 + 1)   => 6
(1 + (2 + 3)) - 4   => 2

We’ll start with a straightforward implementation and optimize it step by step.

YOU CAN FIND THE FULL CODE ON: https://github.com/RPallas92/math_parser


Baseline implementation (43.1 s)

Here’s the first version of our parser:

use std::fs;
use std::io::Result;
use std::{iter::Peekable, time::Instant};

fn main() -> Result()> {
    let total_start = Instant::now();
    let mut step_start = Instant::now();

    let input = read_input_file()?;
   
    println!("Step 1: Input file read in {:?}", step_start.elapsed());

    step_start = Instant::now();
    
    let result = eval(&input);
    
    println!(
        "Step 2: Calculation completed in {:?}",
        step_start.elapsed()
    );

    let total_duration = total_start.elapsed();
    
    println!("--- Summary ---");
    println!("Result: {}", result);
    println!("Total time: {:?}", total_duration);

    Ok(())
}

fn read_input_file() -> ResultString> {
    fs::read_to_string("data/input.txt")
}

fn eval(input: &str) -> u32 {
    let mut tokens = tokenize(input).into_iter().peekable();
    parse_expression(&mut tokens)
}

fn tokenize(input: &str) -> VecToken> {
    input
        .split_whitespace()
        .map(|s| match s {
            "+" => Token::Plus,
            "-" => Token::Minus,
            "(" => Token::OpeningParenthesis,
            ")" => Token::ClosingParenthesis,
            n => Token::Operand(n.parse().unwrap()),
        })
        .collect()
}

fn parse_expression(tokens: &mut Peekableimpl IteratorItem = Token>>) -> u32 {
    let mut left = parse_primary(tokens);

    while let Some(Token::Plus) | Some(Token::Minus) = tokens.peek() {
        let operator: OptionToken> = tokens.next();
        let right = parse_primary(tokens);
        left = match operator {
            Some(Token::Plus) => left + right,
            Some(Token::Minus) => left - right,
            other => panic!("Expected operator, got {:?}", other),
        }
    }

    return left;
}

fn parse_primary(tokens: &mut Peekableimpl IteratorItem = Token>>) -> u32 {
    match tokens.peek() {
        Some(Token::OpeningParenthesis) => {
            tokens.next(); // consume '('
            let val = parse_expression(tokens);
            tokens.next(); // consume ')'
        }
        _ => parse_operand(tokens),
    }
}

fn parse_operand(tokens: &mut Peekableimpl IteratorItem = Token>>) -> u32 {
    match tokens.next() {
        Some(Token::Operand(n)) => n,
        other => panic!("Expected number, got {:?}", other),
    }
}

#[derive(Debug, Clone, PartialEq)]
enum Token {
    Operand(u32),
    Plus,
    Minus,
    OpeningParenthesis,
    ClosingParenthesis,
}

How it works

Let’s break it down.

The program reads from a file called input.txt, which contains a math expression in a single line. That expression is passed to the eval() function.

The tokenize() function processes the input string, splitting it by whitespace and converting each segment into a token. For example, this input:

…is turned into this list of tokens:

[Operand(7), Minus, Operand(3), Plus, Operand(1)]

The parser then uses a simple recursive strategy:

  • parse_expression() handles sequences of additions and subtractions.
  • parse_primary() handles numbers and expressions inside parentheses.
  • parse_operand() handles the actual integer values.

The recursive call to parse_expression() inside parse_primary() allows us to evaluate nested expressions (parentheses).


Parser Example: (1 + 2) – 3

Let’s walk through parsing the expression (1 + 2) - 3 using our functions:

fn eval(input: &str) -> u32 {
    let mut tokens = tokenize(input).peekable();
    parse_expression(&mut tokens)
}

Input string: (1 + 2) - 3

Tokens with index:

Index Token
0 OpeningParenthesis (
1 Operand(1)
2 Plus +
3 Operand(2)
4 ClosingParenthesis )
5 Minus -
6 Operand(3)

We begin by calling parse_expression at depth 1:

  1. parse_expression (depth 1)
    • Calls parse_primary to get the first value.
  2. parse_primary (depth 2)
    • Sees OpeningParenthesis at index 0.
    • Consumes ( and calls parse_expression (depth 3) for the parenthesized subexpression.
  3. parse_expression (depth 3)
    • Calls parse_primary (depth 4).
  4. parse_primary (depth 4)
    • Sees Operand(1) at index 1.
    • Calls parse_operand (depth 5), which consumes index 1 and returns 1.
  5. parse_expression (depth 3) (resuming)
    • Sees Plus at index 2.
    • Consumes + and calls parse_primary (depth 4) again.
  6. parse_primary (depth 4)
    • Sees Operand(2) at index 3.
    • Calls parse_operand (depth 5), which consumes index 3 and returns 2.
  7. parse_expression (depth 3)
    • Combines 1 + 2 = 3.
    • Returns 3 to the caller at depth 2.
  8. parse_primary (depth 2) (resuming)
    • Now at index 4 sees ClosingParenthesis.
    • Consumes ) and returns the inner value 3.
  9. parse_expression (depth 1) (resuming)
    • Left side is 3.
    • Sees Minus at index 5.
    • Consumes - and calls parse_primary (depth 2).
  10. parse_primary (depth 2)
    • Sees Operand(3) at index 6.
    • Calls parse_operand (depth 5), consumes it, and returns 3.
  11. parse_expression (depth 1)
    • Computes 3 - 3 = 0.
    • No more operators, so it returns 0 as the final result.

It works! But we can do better

This baseline parser works well, but it’s not optimized.

If we compile it in release mode and execute it for the test file of 1.5GB, it takes 43.87 seconds to execute on my laptop:

Step 1: Input file read in 1.189915008s
Step 2: Calculation completed in 41.876205675s

--- Summary ---
Result: 2652
Total time: 43.06795088s

While the current parser is correct, its 43-second runtime shows there is room for improvement. Our goal is to make it faster and more memory-efficient.

We will improve the parser’s performance through several key optimizations:

  • Eliminate unnecessary allocations: First, we’ll change the tokenizer to avoid creating a list of tokens in memory.
  • Process bytes directly: We’ll modify the parser to read raw bytes instead of string slices, reducing overhead.
  • Parallelize the work: We’ll use multithreading and SIMD to perform calculations in parallel.
  • Optimize file I/O: Finally, we’ll use memory-mapped files to speed up file reading.

Let’s get started.


Optimizations for speed and memory

Optimization 1: Do not allocate a Vector when tokenizing (43.1 s → 6.45 s, –85% improvement)

Let’s use cargo flamegraph to visualize the call stack of the current solution and identify areas for optimization.

cargo flamegraph --dev --bin parser

We get the following flame graph:

First flamegraph

We can see that the majority of the time is spent in the tokenizer function, which reads the input string and allocates a vector of tokens.

To profile memory usage, we can use dhat to generate a profile JSON file and view it at https://nnethercote.github.io/dh_view/dh_view.html:

First memory profiling

Notice how 4 GB of RAM is used just to allocate the token vector!


I made a mistake in my initial implementation. Why does the tokenize function return a vector if we’re converting it into an iterator later anyway? Let’s just return a lazy iterator directly instead of allocating a vector:

fn eval(input: &str) -> u32 {
    let mut tokens = tokenize(input).peekable();
    parse_expression(&mut tokens)
}

fn tokenize(input: &str) -> impl IteratorItem = Token> + '_ {
    input.split_whitespace().map(|s| match s {
        "+" => Token::Plus,
        "-" => Token::Minus,
        "(" => Token::OpeningParenthesis,
        ")" => Token::ClosingParenthesis,
        n => Token::Operand(n.parse().unwrap()),
    })
}

If we run the parser again after this small change, the speed improves significantly:

Step 1: Input file read in 1.249408413s
Step 2: Calculation completed in 5.204344393s

--- Summary ---
Result: 2652
Total time: 6.45377661s

Wow! From 43 seconds down to just 6.45. What an improvement. A small mistake can have a huge impact on performance. Fortunately, the flamegraph pointed us straight to the bottleneck!


Optimization 2: Zero allocations — parse directly from the input bytes (6.45 s → 3.68 s, –43% improvement)

After removing the initial Vec allocation, performance improved significantly. But we can still do better.

If we analyze the flamegraph again, we notice that although we no longer allocate a vector of tokens, we’re still splitting the input string by whitespace. This iterator-based approach is a huge improvement, but there is still overhead in processing the string and creating &str slices for each token:

Second flamegraph

The pink/violet boxes correspond to the split_whitespace function used by our tokenizer:

fn tokenize(input: &str) -> impl IteratorItem = Token> + '_ {
    input.split_whitespace().map(|s| match s {
        "+" => Token::Plus,
        "-" => Token::Minus,
        "(" => Token::OpeningParenthesis,
        ")" => Token::ClosingParenthesis,
        n => Token::Operand(n.parse().unwrap()),
    })
}

We’re paying a cost for each split_whitespace call, which allocates intermediate slices. This churns memory and CPU cycles.

Let’s dive deeper.

The idea: Use &[u8]

Instead of working with UTF-8 strings and &str, we can use raw bytes (&[u8]) and manually scan for digits and operators to avoid temporary string allocations.

Here is our new zero-allocation tokenizer:

fn read_input_file() -> ResultVecu8>> {
    fs::read("data/input.txt")
}

struct Tokenizer'a> {
    input: &'a [u8],
    pos: usize,
}

impl'a> Iterator for Tokenizer'a> {
    type Item = Token;

    fn next(&mut self) -> OptionSelf::Item> {
        if self.pos >= self.input.len() {
            return None;
        }

        let byte = self.input[self.pos];

        self.pos += 1;

        let token = match byte {
            b'+' => Some(Token::Plus),
            b'-' => Some(Token::Minus),
            b'(' => Some(Token::OpeningParenthesis),
            b')' => Some(Token::ClosingParenthesis),
            b'0'..=b'9' => {
                let mut value = byte - b'0';
                while self.pos  self.input.len() && self.input[self.pos].is_ascii_digit() {
                    value = 10 * value + (self.input[self.pos] - b'0');
                    self.pos += 1;
                }

                Some(Token::Operand(value))
            }
            other => panic!("Unexpected byte: '{}'", other as char),
        };

        self.pos += 1; // skip whitespace

        return token;
    }
}

The only heap allocation occurs when the file is read into a vector. The tokenizer operates on references to that vector of bytes and does not perform any intermediate allocations.

If we execute the program again, we get:

Step 1: Input file read in 1.212080967s
Step 2: Calculation completed in 2.471639289s

--- Summary ---
Result: 2652
Total time: 3.683753465s

A great improvement! From 6.45 to 3.68 seconds, nearly 2 seconds faster!

Optimization 3: Do not use Peekable (3.68 s → 3.21 s, –13% improvement)

The new flamegraph shows several samples related to Peekable:

  • core::iter::adapters::peekable::Peekable::peek::_
  • core::iter::adapters::peekable::Peekable::peek

Third flamegraph

This is because we wrap our tokenizer in Rust’s Peekable adapter, which allows us to inspect the next token without consuming it. We initially used it for look ahead when parsing expressions like 1 + (2 - 3) to determine whether to continue parsing or return early.

However, in our use case, peek() isn’t necessary. We can restructure the algorithm to work directly with a plain iterator.

Here’s the old version:

fn parse_expression(tokens: &mut Peekableimpl IteratorItem = Token>>) -> u32 {
    let mut left = parse_primary(tokens);

    while let Some(Token::Plus) | Some(Token::Minus) = tokens.peek() {
        let operator = tokens.next();
        let right = parse_primary(tokens);
        left = match operator {
            Some(Token::Plus) => left + right,
            Some(Token::Minus) => left - right,
            other => panic!("Expected operator, got {:?}", other),
        };
    }

    left
}

And here’s the new version that eliminates Peekable:

fn parse_expression(tokens: &mut impl IteratorItem = Token>) -> u32 {
    let mut left = parse_primary(tokens);

    while let Some(token) = tokens.next() {
        if token == Token::ClosingParenthesis {
            break;
        }

        let right = parse_primary(tokens);
        left = match token {
            Token::Plus => left + right,
            Token::Minus => left - right,
            other => panic!("Expected operator, got {:?}", other),
        };
    }

    left
}

We replaced the peek() logic with a match on the current token. If it’s a + or -, we consume the right-hand operand and compute the result. If it’s a closing parenthesis, we break (this is an important point: we no longer manually skip the closing parenthesis after parsing a sub-expression).

Previously, with peekable, we consumed the (, parsed the sub-expression, and then had to explicitly next() again to discard the ) after the recursive call. Now, since we’re using a flat iterator, we simply let the closing ) token be returned by next(), and our while let Some(token) loop handles it. If the token is a ), we break out of the loop, and the recursive call returns.

We also simplified parse_primary in a similar way:

fn parse_primary(tokens: &mut impl IteratorItem = Token>) -> u32 {
    match tokens.next() {
        Some(Token::OpeningParenthesis) => {
            let val = parse_expression(tokens);
            val
        }
        Some(Token::Operand(n)) => n as u32,
        other => panic!("Expected number, got {:?}", other),
    }
}

By avoiding peek() and handling the tokens linearly, we improve the performance:

Step 1: Input file read in 1.116952011s
Step 2: Calculation completed in 2.094806113s

--- Summary ---
Result: 2652
Total time: 3.21178544s

From 3.68 to 3.21 seconds. We are getting faster. Let’s continue optimizing!


Optimization 4: Multithreading and SIMD (3.21 s → 2.21 s, –31% improvement)

The next logical step is to parallelize the computation. Ideally, if we have a CPU with 8 cores, we want to split the input file into 8 equal chunks and have each core work on one chunk simultaneously. This should, in theory, make our program up to 8 times faster.

However, this is not as simple as just splitting the file into 8 equal chunks. We are bound by the rules of math and syntax, which introduce two restrictions:

  1. We cannot split inside parentheses. A split can only happen at the “top level” of the expression. For example, splitting ((2 + 1)| - 2) is invalid, and this applies to nested parentheses as well.
  2. We cannot split at a - operator. Addition is associative, meaning (a + b) + c is equivalent to a + (b + c). This property allows us to group additions freely. Subtraction, however, is not associative: (a - b) - c is not the same as a - (b - c). Splitting on a - would alter the order of operations and lead to an incorrect result.

These restrictions mean we cannot simply split the file at (total_size / 8). We need a way to find the closest valid split point (a + sign at the top level) to that ideal boundary.

To find these points, we would need to scan the entire input to identify where all current parentheses are closed. A naive scan for this would be slow, requiring a full pass over the data just to find the split points before the actual work begins. So, is this solution slower (2 passes vs 1 pass)? Not necessarily. We can make the first pass blazing fast by using SIMD.

The algorithm at a high level

Before diving into the code, let’s look at the high-level plan. The entire process is started by our parallel_eval function, which follows this data flow:

[ Input File ]
      |
      v
.-----------------------.
|     parallel_eval     |
'-----------------------'
      |
      | 1. Find Splits
      v
.----------------------------------.
| find_best_split_indices_simd     |------> [ Split Indices ]
'----------------------------------'             |
      |                                          |
      | 2. Create Chunks                         |
      v                                          |
[ Chunk 1 ] [ Chunk 2 ] ... [ Chunk N ] 

What is SIMD?

SIMD stands for Single Instruction, Multiple Data. It’s a powerful feature built into modern CPUs. At its core, SIMD allows the CPU to perform the same operation on multiple pieces of data at the same time, with a single instruction.

Consider a cashier at a grocery store. A traditional CPU core operates like a cashier scanning items one by one. This is a scalar operation, where one instruction processes one piece of data.

Scalar Operation (One by one)
Instruction: Is this byte '+'?
      |
      V
[ H | e | l | l | o |   | + |   | W | o | r | l | d ]
  ^--- Processed sequentially --->

A SIMD-enabled CPU is like a cashier with a wide scanner that can read the barcodes of an entire row of items in the cart simultaneously. This is a vector operation.

SIMD Operation (All at once)
Instruction: For all 64 of these bytes, tell me which ones are '+'?
      |
      V
[ H | e | l | l | o |   | + |   | W | o | r | l | d | ... (up to 64 bytes) ]
[ 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | ... (result mask)  ]
\_______________________________________________________________________/
                         Processed in a single cycle

For repetitive tasks, such as searching for a specific character in a long string, the performance gain is great.

SIMD example: Finding +

In our project, we need to locate all + characters.

The Scalar Way: Without SIMD, we would need a simple for loop to check every single byte:

let mut positions = Vec::new();
for (i, &byte) in input.iter().enumerate() {
    if byte == b'+' {
        positions.push(i);
    }
}

This approach is simple and correct, but for a 1.5GB file like ours, this loop would execute 1.5 billion times.

The SIMD Way: With SIMD (specifically, using AVX-512 instructions), the process is different:

  1. Load: We load a big chunk of our input string (64 bytes at a time) into a wide 512-bit CPU register.
  2. Compare: We use a single instruction (_mm512_cmpeq_epi8_mask) to compare all 64 bytes in our register against a template register that contains 64 copies of the + character.
  3. Get Mask: The CPU returns a single 64-bit integer (u64) as a result. This is a bitmask. If the 5th bit of this integer is 1, it indicates that the 5th byte of our input chunk was a +.

In a single instruction, we have done the work of 64 loop iterations. While SIMD requires more complex code, the performance gains are worth it.

The Code

Here are the two key functions that implement our parallel strategy: parallel_eval orchestrates the process, and find_best_split_indices_simd uses SIMD to find the valid split points.

fn parallel_eval(input: &[u8], num_threads: usize) -> i64 {
    if num_threads  1 || input.len()  1000 {
        return eval(input);
    }

    // 1. Find the best places to split the input.
    let split_indices = unsafe { find_best_split_indices_simd(input, num_threads - 1) };

    if split_indices.is_empty() {
        return eval(input);
    }

    // 2. Create the chunks based on the indices.
    let mut chunks = Vec::with_capacity(num_threads);
    let mut last_idx = 0;
    for &idx in &split_indices {
        // Slice from the last index to just before the operator's space.
        chunks.push(&input[last_idx..idx - 1]);
        // The next chunk starts after the operator and its space.
        last_idx = idx + 2;
    }
    chunks.push(&input[last_idx..]);

    // 3. Process all chunks in parallel with Rayon.
    let chunk_results: Veci64> = chunks.par_iter().map(|&chunk| eval(chunk)).collect();

    // 4. Since we only split on '+', the final result is the sum of all parts.
    chunk_results.into_iter().sum()
}

#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx512f")]
#[target_feature(enable = "avx512bw")]
unsafe fn find_best_split_indices_simd(input: &[u8], num_splits: usize) -> Vecusize> {
    // Explanation of this function in the next section.
    let mut final_indices = Vec::with_capacity(num_splits);
    if num_splits == 0 {
        return final_indices;
    }

    let chunk_size = input.len() / (num_splits + 1);
    let mut target_idx = 1;
    let mut last_op_at_depth_zero = 0;
    let mut depth: i32 = 0;
    let mut i = 0;
    let len = input.len();

    let open_parens = _mm512_set1_epi8(b'(' as i8);
    let close_parens = _mm512_set1_epi8(b')' as i8);
    let pluses = _mm512_set1_epi8(b'+' as i8);

    'outer: while i + 64  len {
        if final_indices.len() >= num_splits {
            break;
        }
        let chunk = _mm512_loadu_si512(input.as_ptr().add(i) as *const _);
        let open_mask = _mm512_cmpeq_epi8_mask(chunk, open_parens);
        let close_mask = _mm512_cmpeq_epi8_mask(chunk, close_parens);
        let plus_mask = _mm512_cmpeq_epi8_mask(chunk, pluses);

        let mut all_interesting_mask = open_mask | close_mask | plus_mask;

        while all_interesting_mask != 0 {
            let j = all_interesting_mask.trailing_zeros() as usize;
            let current_idx = i + j;
            if (open_mask >> j) & 1 == 1 {
                depth += 1;
            } else if (close_mask >> j) & 1 == 1 {
                depth -= 1;
            } else { // Is a '+' operator
                if depth == 0 {
                    last_op_at_depth_zero = current_idx;
                    let ideal_pos = target_idx * chunk_size;
                    if current_idx >= ideal_pos {
                        final_indices.push(current_idx);
                        target_idx += 1;
                        if final_indices.len() >= num_splits {
                            break 'outer;
                        }
                    }
                }
            }
            all_interesting_mask &= all_interesting_mask - 1;
        }
        i += 64;
    }

    // ... scalar remainder and fill logic ...
    while i  len && final_indices.len()  num_splits {
        let char_byte = *input.get_unchecked(i);
        if char_byte == b'(' { depth += 1; }
        else if char_byte == b')' { depth -= 1; }
        else if char_byte == b'+' && depth == 0 {
            last_op_at_depth_zero = i;
            let ideal_pos = target_idx * chunk_size;
            if i >= ideal_pos {
                final_indices.push(i);
                target_idx += 1;
            }
        }
        i += 1;
    }
    while final_indices.len()  num_splits && last_op_at_depth_zero > 0 {
        final_indices.push(last_op_at_depth_zero);
    }
    final_indices
}

Algorithm Breakdown: find_best_split_indices_simd

This function’s purpose is to identify the optimal + signs for splitting.

Step 1: The SIMD Scan

The code enters a main loop, processing the input in 64-byte chunks. Within this loop, it uses _mm512_cmpeq_epi8_mask to generate bitmasks. This instruction compares all 64 bytes of the current chunk against a target character and returns a 64-bit integer (u64) where the N-th bit is 1 if the N-th byte was a match.

Step 2: The serial scan

Next, we combine these masks and iterate only through the “interesting” bits. This is a key step:

let mut all_interesting_mask = open_mask | close_mask | plus_mask; // This means we are looking for '(', ')' and '+' characters.

while all_interesting_mask != 0 {
    let j = all_interesting_mask.trailing_zeros() as usize; // j is the index of the next found interesting character.
    let current_idx = i + j; // + j because the mask is a u64 little endian, so trailing zeros are the leading 0 in reality
    if (open_mask >> j) & 1 == 1 { // If that char is a '(' we increase the depth (we enter in a sub expression)
        depth += 1;
    } else if (close_mask >> j) & 1 == 1 { // If that char is a ')' we decrease the depth (we exit from a sub expression)
        depth -= 1;
    } else {
        if depth == 0 { // If the depth is 0, we are at a top level, outside of parentheses. And it is a '+' sign.
            last_op_at_depth_zero = current_idx;
            if current_idx >= ideal_pos { // If we have reached the ideal position (chunk / NUM_THREADS). So we add this '+' sign to the splitting indices.
                final_indices.push(current_idx);
                target_idx += 1;
                if final_indices.len() >= num_splits {
                    break 'outer;
                }
            }
        }
    }
    all_interesting_mask &= all_interesting_mask - 1; // Clears the lowest set 1 bit from the mask, as we have processed it already
}

This loop does not run 64 times. It only runs for the number of set bits in all_interesting_mask. To understand how it processes characters from left-to-right, we need to look at two key details:

  1. trailing_zeros() and Little-Endian: While you might assume trailing_zeros starts from the end of the string, it’s actually the opposite. Modern x86-64 CPUs are little-endian. When a block of memory is loaded into a large integer register, the first byte in memory (e.g., chunk[0]) becomes the least significant byte (LSB) of the integer. The trailing_zeros() instruction counts from this LSB, meaning it always finds the set bit corresponding to the character with the lowest index in our chunk.

    Memory (Bytes in a chunk):
      Byte Index:   0   1   2   3   ...   63
      Content:     '(' '1' '+' '2'  ...   'X'
    
          |
          |  Load into a 64-bit integer
          v
    
    Resulting u64 Bitmask:
      Bit Position:  63  ...   3   2   1   0   

    As you can see, trailing_zeros starts from the right of the integer, which corresponds to the left of our string chunk.

  2. if (open_mask >> j) & 1 == 1 {: This is just to check if there is an open parenthesis at position j. If so, we increment our counter depth.

  3. all_interesting_mask &= all_interesting_mask - 1: This is a trick that clears the lowest set 1 bit we just found. On the next iteration, trailing_zeros finds the new lowest set bit, which corresponds to the character at the next lowest index.

This combination allows us to visit every interesting character in the correct, forward order, but without a slow byte-by-byte scan. Inside the loop, we just update our depth counter to know if we are at a top level position, and if so, we check if we can add a splitting point.

Full example

Let’s trace the entire flow with a small, concrete example:

  • Input String: (1-2) + (3-4) + (5-6) (Length is 23 bytes)
  • Goal: Find 1 split point (num_splits = 1) to create 2 chunks.
  • Ideal Split Position: 1 * (23 / 2) = 11. We are looking for the first + at depth 0 at or after byte 11.
Part 1: find_best_split_indices_simd runs

The function will scan the input to find the best split point.

Input:        ( 1 - 2 )   +   ( 3 - 4 )   +   ( 5 - 6 )
Index:        0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2
                                  1 1 1 1 1 1 1 1 1 1 2 2 2
Depth:        1 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 0 0
Ideal Split ->                      ^
  1. The code starts scanning. It finds the first + at index 7.
  2. It checks the depth. The ( at index 0 increased depth to 1, and the ) at index 5 decreased it back to 0. So, at index 7, depth == 0.
  3. It checks the splitting logic: is current_idx (7) >= ideal_pos (11)? The answer is No. The code continues scanning.
  4. The code finds the next + at index 15.
  5. It checks the depth. The ( at index 9 and ) at index 13 have kept the depth at 0.
  6. It checks the splitting logic: is current_idx (15) >= ideal_pos (11)? The answer is Yes!
  7. Action: The code pushes 15 into final_indices and immediately breaks out of all loops because it has found the 1 split it was looking for.
  8. The function returns [15].
Part 2: parallel_eval receives the result
  1. split_indices is now [15].
  2. The for loop runs once for the index 15.
    • It creates the first chunk by slicing from 0 to 15 - 1 = 14. The chunk is (1-2) + (3-4).
    • It updates last_idx to 15 + 2 = 17.
  3. The loop finishes. It creates the final chunk by slicing from 17 to the end. The chunk is (5-6).

    Original:     (1-2) + (3-4)   +   (5-6)
                     
    
    Split Index:                    ^ (15)
    
  4. The two chunks, (1-2) + (3-4) and (5-6), are sent to the Rayon thread pool.
  5. Thread 1 gets (1-2) + (3-4), calls eval, and gets the result -2.
  6. Thread 2 gets (5-6), calls eval, and gets the result -1.
  7. collect() gathers the results into a vector: [-2, -1].
  8. Finally, sum() adds them together: -2 + -1 = -3.

The final answer is -3, which is correct. The entire process worked perfectly.

Result

In summary, by using SIMD, we can perform an initial, extremely fast pass to identify optimal split points in the input, and then process each chunk in parallel. I believe a similar technique is employed by the popular simdjson library.

I executed the code on my Surface laptop, and here are the results:

Step 1: Input file read in 1.199915008s

Step 2: Calculation completed in 1.010507822s

--- Summary ---
Result: 2652
Total time: 2.210422830s

From 3.21 to 2.21 seconds. 1 second faster, for an already optimized program. Good!


Optimization 5: Memory-Mapped I/O (2.21 s → 0.98 s, –56% improvement)

After profiling the memory usage of our parallel solution, we can see that we’re still allocating a very large buffer on the heap to hold the entire file’s contents.

mmap (memory-mapped files) can be more efficient than standard file I/O because it avoids extra copying from kernel to user space, and allows the operating system to manage memory for us.

When I initially tried mmap with the single-threaded version of the code, the performance gain was negligible. However, now that our program is multithreaded, let’s re-evaluate its impact.

Kernel Space vs. User Space

  • Kernel space: The privileged area where the operating system runs, managing hardware, I/O, and the page cache.
  • User space: The unprivileged area where our application code executes, including your heap buffers, stacks, and other program data.
  • Page cache: A kernel-managed buffer that temporarily stores file data in memory to speed up subsequent access.

Cost of fs::read

  1. Double Memory Footprint
    [ Disk ] → [ Page Cache ] (1.5 GB)  
              → [ Heap Vec ] (1.5 GB)  
    

    This process involves loading the file into kernel space and then copying it to user space.

  2. False Sharing Contention Modern CPUs transfer data between main memory and CPU caches in 64-byte blocks called “cache lines.” False sharing occurs when multiple threads access different variables that happen to reside on the same cache line. If one thread modifies its variable, the entire cache line is invalidated for all other threads, forcing them to re-fetch it from memory even though their own data hasn’t changed.
    // Thread 1 writes to data at byte 8
    // Thread 2 writes to data at byte 40
    // Both bytes are in the same 64-byte cache line (0-63).
    // The cache line "bounces" between the cores, causing delays.
    

    With a single large Vec, the boundaries of the chunks processed by each thread could easily fall in a way that causes this contention.

mmap improvement

Instead of reading the entire file into a Vec, we can map it directly into memory with mmap. This gives us:

use memmap2::Mmap;

fn read_input_file() -> std::io::ResultMmap> {
    let file = File::open("data/input.txt")?;
    unsafe { Mmap::map(&file) }
}

This approach avoids the extra copy performed by fs::read and does not allocate the file’s content in user space memory.

[ Disk ] → [ Page Cache (1.5 GB) ] ↔ [ mmap view in user space ]

I also think it is faster because we don’t have false sharing with mmap. It hands us the file in 4 KB pages. Threads get whole pages:

Thread 1 works on data starting at Page 0 (byte 0)
Thread 2 works on data starting at Page N (byte N*4096)

Since pages (4 KB) are much larger than cache lines (64 B), threads operate on memory regions that are physically far apart, preventing them from contending over the same cache lines. I’m not entirely certain about this, but it’s my conclusion after reading a lot about the topic and consulting various LLM models.

Code Changes

The change is minimal. The read_input_file function now returns an Mmap object, which is passed directly to the parallel_eval function. This allows the operating system to efficiently map the file directly into our process memory on demand:

use memmap2::Mmap;

fn read_input_file() -> ResultMmap> {
    let file = File::open("data/input.txt")?;
    unsafe { Mmap::map(&file) }
}

fn main() -> Result()> {
    let mmap = read_input_file()?;
    let result = parallel_eval(&mmap, NUM_THREADS);
    println!("Result: {}", result);
    Ok(())
}

Performance Results

Step 1: Input file read in 18.8 µs  
Step 2: Calculation completed in 981.2 ms  
**Total time:** 981.3 ms

From 2.21s to 981ms. Less than a second!!


Conclusion

YOU CAN FIND THE FULL CODE ON: https://github.com/RPallas92/math_parser

We started with a simple math parser that took 43 seconds to run. By making a series of changes, we made it run in under one second. Here is a summary of what we did:

  1. Stopped creating a list of all tokens at once. Instead of reading the whole file and creating a big list of tokens, we processed them one by one. This was the biggest improvement, bringing the time down from 43 to 6.4 seconds. (To be honest I made this mistake in purpose just to see the difference).
  2. Worked with bytes instead of text. Instead of treating the input as text, we worked with the raw bytes. This avoided extra work and brought the time down to 3.7 seconds.
  3. Simplified the code by removing Peekable. We changed the logic to avoid peeking at the next token, which made the code faster, reducing the time to 3.2 seconds.
  4. Used multiple threads and modern CPU features. We used Rayon to run calculations in parallel and SIMD to find split points faster. This brought the time down to 2.2 seconds.
  5. Used memory-mapped files. Instead of reading the file into memory ourselves, we let the operating system handle it. This was the final optimization, bringing the time down to just 0.98 seconds.

If you have any corrections or comments, please contact me on LinkedIn or via email. Thank you very much for reading!

« Pingora async runtime and threading model
Ricardo Pallas

Ricardo Pallas

λ Software Engineer

Ricardo Pallás © 2025

Source Link


Keep your files stored safely and securely with the SanDisk 2TB Extreme Portable SSD. With over 69,505 ratings and an impressive 4.6 out of 5 stars, this product has been purchased over 8K+ times in the past month. At only $129.99, this Amazon’s Choice product is a must-have for secure file storage.

Help keep private content private with the included password protection featuring 256-bit AES hardware encryption. Order now for just $129.99 on Amazon!


Unlock unlimited streaming with a free Amazon Prime trial!
Sign up today!

Help Power Techcratic’s Future – Scan To Support

If Techcratic’s content and insights have helped you, consider giving back by supporting the platform with crypto. Every contribution makes a difference, whether it’s for high-quality content, server maintenance, or future updates. Techcratic is constantly evolving, and your support helps drive that progress.

As a solo operator who wears all the hats, creating content, managing the tech, and running the site, your support allows me to stay focused on delivering valuable resources. Your support keeps everything running smoothly and enables me to continue creating the content you love. I’m deeply grateful for your support, it truly means the world to me! Thank you!

BITCOIN

Bitcoin Logo

Bitcoin QR Code

bc1qlszw7elx2qahjwvaryh0tkgg8y68enw30gpvge

Scan the QR code with your crypto wallet app

DOGECOIN

Dogecoin Logo

Dogecoin QR Code

D64GwvvYQxFXYyan3oQCrmWfidf6T3JpBA

Scan the QR code with your crypto wallet app

ETHEREUM

Ethereum Logo

Ethereum QR Code

0xe9BC980DF3d985730dA827996B43E4A62CCBAA7a

Scan the QR code with your crypto wallet app

Please read the Privacy and Security Disclaimer on how Techcratic handles your support.

Disclaimer: As an Amazon Associate, Techcratic may earn from qualifying purchases.

Tags: Hacker News
Share162Share28ShareShare4ShareTweet101
Hacker News

Hacker News

Stay updated with Hacker News, where technology meets entrepreneurial spirit. Get the latest on tech trends, startup news, and discussions from the tech community. Read the latest updates here at Techcratic.

Related Posts

twitter/the-algorithm: Source code for the X Recommendation Algorithm
Hacker News

twitter/the-algorithm: Source code for the X Recommendation Algorithm

September 9, 2025
1.3k
Microsoft to Add New AI-Powered Actions in File Explorer
Hacker News

Microsoft to Add New AI-Powered Actions in File Explorer

September 9, 2025
1.3k
Data from Police Body Camera Apps Routed to Chinese Cloud Servers Over TLS Port 9091
Hacker News

Data from Police Body Camera Apps Routed to Chinese Cloud Servers Over TLS Port 9091

September 9, 2025
1.3k
New Exploitation Method Discovered for Linux Kernel Use-After-Free Vulnerability
Hacker News

New Exploitation Method Discovered for Linux Kernel Use-After-Free Vulnerability

September 9, 2025
1.3k
MostereRAT Exploits AnyDesk and TightVNC for Remote Access on Windows Systems
Hacker News

MostereRAT Exploits AnyDesk and TightVNC for Remote Access on Windows Systems

September 9, 2025
1.3k
Strong Eventual Consistency – The Big Idea behind CRDTs
Hacker News

Strong Eventual Consistency – The Big Idea behind CRDTs

September 9, 2025
1.3k
Setting up a home VPN server with Wireguard
Hacker News

Setting up a home VPN server with Wireguard

September 8, 2025
1.3k
npm debug and chalk packages compromised
Hacker News

npm debug and chalk packages compromised

September 8, 2025
1.3k
Load More
Next Post
Playful kittens love their new box #cat #kitten #cute #catlover

Playful kittens love their new box #cat #kitten #cute #catlover

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Your Tech Resources

  • 30 Second Tech ™
  • AI
  • App Zone ™
  • Apple
  • Ars Technica
  • CNET
  • ComputerWorld
  • Crypto News
  • Cybersecurity
  • Endgadget
  • ExtremeTech
  • Forbes
  • Fossbytes
  • Gaming
  • GeekWire
  • Gizmodo
  • Google News
  • Hacker News
  • Harvard Tech
  • I Like Cats ™
  • I Like Dogs ™
  • LifeHacker
  • MacRumors
  • Macworld
  • Mashable
  • Microsoft
  • MIT Tech
  • PC World
  • Photofocus
  • Physics
  • Random Tech
  • Retro Rewind ™
  • Robot Report
  • SiliconANGLE
  • SlashGear
  • Smartphone
  • StackSocial
  • Tech Art
  • Tech Careers
  • Tech Deals
  • Techcratic ™
  • TechCrunch
  • Techdirt
  • TechRepublic
  • Techs Got To Eat ™
  • TechSpot
  • Tesla
  • The Verge
  • TNW
  • Trusted Reviews
  • UFO
  • VentureBeat
  • Visual Capitalist
  • Wired
  • ZDNet

Tech News

  • 30 Second Tech ™
  • AI
  • Apple Insider
  • Ars Technica
  • CNET
  • ComputerWorld
  • Crypto News
  • Cybersecurity
  • Endgadget
  • ExtremeTech
  • Fossbytes
  • Gaming
  • GeekWire
  • Gizmodo

Tech News

  • Harvard Tech
  • MacRumors
  • Macworld
  • Mashable
  • Microsoft
  • MIT Tech
  • Physics
  • PC World
  • Random Tech
  • Retro Rewind ™
  • SiliconANGLE
  • SlashGear
  • Smartphone
  • StackSocial
  • Tech Careers

Tech News​

  • Tech Art
  • TechCrunch
  • Techdirt
  • TechRepublic
  • Techs Got To Eat ™
  • TechSpot
  • Tesla
  • The Verge
  • TNW
  • Trusted Reviews
  • UFO
  • VentureBeat
  • Visual Capitalist
  • Wired
  • ZDNet

Site Links

  • About Techcratic
  • Affiliate Disclaimer
  • Affiliate Link Policy
  • Contact Techcratic
  • Dealors Discount Store
  • Privacy and Security Disclaimer
  • Privacy Policy
  • RSS Feed
  • Site Map
  • Support Techcratic
  • Techcratic
  • Tech Deals
  • TOS
  • 𝕏
Click For A Secret Deal

Apple announces iPhone 17 with ProMotion display and upgraded selfie cam

iPhone Air vs iPhone 17: What’s the difference?

Enterprise security threats will be key focus at Fal.Con

Bitcoin On The Rocks After Shocking US Jobs Revision

ASRock AMD Radeon RX 9070 XT Steel Legend 16GB, Boost Clock Up to 2970 MHz / 20 Gbps,…

How Agentic AI Is Shaping Business Value For Enterprises

Techcratic – Your All In One Tech Hub
© 2020 – 2025
All Rights Reserved
∞

No Result
View All Result
  • 30 Second Tech ™
  • AI
  • App Zone ™
  • Apple
  • Ars Technica
  • CNET
  • Crypto News
  • Cybersecurity
  • Endgadget
  • Gaming
  • I Like Cats ™
  • I Like Dogs ™
  • MacRumors
  • Macworld
  • Tech Deals
  • Techcratic ™
  • Techs Got To Eat ™
  • Tesla
  • UFO
  • Wired