Supporting data structures for SAT local search
The needed data structure is an occur list, a list for each variable containing the clauses the variable occurs in.  These lists are built once, when the CNF is first read.   They are used in steps 3 and 5 below to avoid scanning the whole CNF formula to count satisfied clauses.

A better algorithm than flipping every variable is:


Make a list of only the variables that occur in the unsatisfied clauses.
Choose a variable $x$ from this list.
Count how many clauses that contain $x$ are satisfied.
Flip $x$.
Count how many clauses that contain $x$ are satisfied.
Unflip $x$.
Subtract the result of step 3 from step 5 and record it for $x$.
Repeat steps 2-7 for the rest of the variables found in step 1.
Flip the variable with the highest number recorded in step 7.


A reference for the data structure (often also known as an adjacency list) is for example Lynce and Marques-Silva, Efficient Data Structures for Backtracking SAT solvers, 2004.