Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of SQL generation by using deepcopy less #2212

Merged
merged 1 commit into from
Jun 18, 2024

Conversation

RobinL
Copy link
Member

@RobinL RobinL commented Jun 18, 2024

Fixes #2210

This takes 2 seconds before, 0.1 second after this PR

example
import time

from splink.blocking import block_using_rules_sqls
from splink.datasets import splink_datasets
from splink.duckdb.blocking_rule_library import block_on
from splink.duckdb.comparison_library import (
    exact_match,
    levenshtein_at_thresholds,
)
from splink.duckdb.linker import DuckDBLinker

df = splink_datasets.fake_1000

settings = {
    "probability_two_random_records_match": 0.01,
    "link_type": "dedupe_only",
    "blocking_rules_to_generate_predictions": [
        block_on(["first_name"]),
        block_on(["surname"]),
        block_on(["dob"]),
        block_on(["city"]),
        block_on(["email", "city", "first_name"]),
    ],
    "comparisons": [
        levenshtein_at_thresholds("first_name", 2),
        exact_match("surname"),
        exact_match("dob"),
        exact_match("city", term_frequency_adjustments=True),
        exact_match("email"),
    ],
    "retain_intermediate_calculation_columns": True,
    "additional_columns_to_retain": [
        "cluster",
        "surname",
        "email",
        "city",
        "dob",
        "first_name",
    ],
}


linker = DuckDBLinker(df, settings)

start_time = time.time()
block_using_rules_sqls(linker)
end_time = time.time()
print(f"Blocking took {end_time - start_time} seconds")

Deepcopy was resulting in the settings object being copied repeatedly I think - in any case, a shallow copy is sufficient becasue the only thing that is being copied is the column builder

@samnlindsay samnlindsay self-requested a review June 18, 2024 09:51
Copy link
Contributor

@samnlindsay samnlindsay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RobinL RobinL merged commit 7b70d6b into master Jun 18, 2024
10 checks passed
@RobinL RobinL deleted the improve_performance_of_sql_generation branch June 18, 2024 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Splink3: Very poor performance of block_using_rules_sqls due to repeated calls to
2 participants