The phrase by a long chalk, also a long chalk, by long chalks, by chalks, means in a great degree, by far.
It originated in the practice of using chalk to mark up the points scored in a game. The following from Bell’s Life in London and Sporting Chronicle (London) of Sunday 15th February 1863 illustrates this practice:
DOMINOES.—A match was played between T. Bishop, the blind Champion domino player of England, and J. Coward, the blind Leeds player, for £5 a side, on Wednesday, Feb. 11. The game was double sixes, seven dominoes each, 21 chalks game. Coward won the down, and started off in gallant style by scoring the first six chalks. The Champion, nothing daunted, got the next two, Coward the next, the Champion, by spirited play, scored the next three. Coward getting the next two, the Champion then followed by scoring four more chalks, making the game nine each. They then played a splendid game, getting almost chalk for chalk, until they had scored 17 each, when the Champion had the game all his own way, never allowing Coward to get another chalk. The game, which was cleverly played throughout, was thus won by the Champion by four chalks.
The earliest instance of the phrase that I have found is in an abstruse paragraph from The Boston Morning Post (Boston, Massachusetts) of 30th November 1833:
Might your name be Smith, said a lout to that oddest of odd fellows, I, after a rap at his door loud enough to disturb the occupants of a church-yard. Yes it might, but it aint [sic] by a long chalk.
This story must have been comprehensible at that time, since The Picayune (New Orleans, Louisiana) of 31st May 1837 republished it:
Correct Answer.—“Might your name be Smith?” said a lout to that oddest of odd fellows, I——, after a rap at the door loud enough to disturb the occupants of a church-yard. “Yes, it might, but it aint [sic] by a long chalk.”
On 28th November 1840, The Vindicator (Belfast, Ireland) published an exchange of heated letters between two members of the clergy, John Hurst and W. Barlee, the latter accusing the former of having shot two pigs that belonged to a poor woman and had trespassed into his garden; the newspaper concluded:
We will back this against the filthiest pasquinade in Swift¹, or the most piquant piece of ribaldry in Watty Cox’s Magazine², or the Evening Packet³, for pure, downright, unadulterated, and unhesitating blackguardism. It beats them all by chalks. People wonder that dissent is spreading over England, and that even Socialism is gaining ground; how can they be so silly as to wonder, when the men paid for conserving the public morals are Barlees and Hursts!
We do not say, because we cannot think it possible, that any considerable proportion of the English clergy are so lost to shame and decency; but we do ask, unhesitatingly, if it is conceivable that even two such persons could be found among the clergy of any Christian persuasion depending upon voluntary support?
¹ the Irish satirist, poet and Anglican cleric Jonathan Swift (1667-1745)
² The Irish Magazine, or Monthly Asylum for Neglected Biography, a scurrillous periodical established by the Irish journalist and informer Walter ‘Watty’ Cox (circa 1770-1837)
³ The Evening Packet, a Dublin newspaper